To
How do I use To
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: ClassBLL.cs
Copy
15 public void ChuanBi3Table(string MaHK)
16 {
17 //Table 1
18 string sql1 = " select MaSV,'sotinchi'=sum(SoTC) " +
19 " from KetQua kq,HocPhan hp,NhomHocPhan nhp,KeHoachGiangDay khgd " +
20 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khgd.MaKHGD=nhp.MaKHGD and MaHK='" + MaHK + "' " +
21 " group by MaSV ";
22 DataTable dt1 = da.GetTable(sql1);
23 for (int i = 0; i < dt1.Rows.Count; i++)
24 {
25 string sql_1 = "Insert into Loptc values('" + dt1.Rows[i][0] + "'," + dt1.Rows[i][1] + ")";
26 da.ExcuteNonQuery(sql_1);
27 }
28 //Table 2
29 string sql2 = "select MaSV,'cuoiky'=sum(DiemTk10*SoTC) " +
30 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
31 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaHK='" + MaHK + "' " +
32 " group by MaSV ";
33 DataTable dt2 = da.GetTable(sql2);
34 for (int i = 0; i < dt2.Rows.Count; i++)
35 {
36 string sql_2 = "Insert into Lopdiem10 values('" + dt2.Rows[i][0] + "'," + dt2.Rows[i][1] + ")";
37 da.ExcuteNonQuery(sql_2);
38 }
39 //Table 3
40 string sql3 = " select Lopdiem10.MaSV,'TrungBinhCuoiKyHe10'=cuoiky/sotinchi " +
41 " from Lopdiem10 left join Loptc on Loptc.MaSV=Lopdiem10.MaSV";
42 DataTable dt3 = da.GetTable(sql3);
43 for (int i = 0; i < dt3.Rows.Count; i++)
44 {
45 string sql_3 = "Insert into DTB values('" + dt3.Rows[i][0] + "'," + dt3.Rows[i][1] + ")";
46 da.ExcuteNonQuery(sql_3);
47 }
48 }
File name: ClassBLL.cs
Copy
49 public void ChuanBi3Table()
50 {
51 //Table 1
52 string sql1 = " select MaSV,'sotinchi'=sum(SoTC) " +
53 " from KetQua kq,HocPhan hp,NhomHocPhan nhp,KeHoachGiangDay khgd " +
54 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khgd.MaKHGD=nhp.MaKHGD " +
55 " group by MaSV ";
56 DataTable dt1 = da.GetTable(sql1);
57 for (int i = 0; i < dt1.Rows.Count; i++)
58 {
59 string sql_1 = "Insert into Loptc values('" + dt1.Rows[i][0] + "'," + dt1.Rows[i][1] + ")";
60 da.ExcuteNonQuery(sql_1);
61 }
62 //Table 2
63 string sql2 = "select MaSV,'cuoiky'=sum(DiemTk10*SoTC) " +
64 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
65 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD " +
66 " group by MaSV ";
67 DataTable dt2 = da.GetTable(sql2);
68 for (int i = 0; i < dt2.Rows.Count; i++)
69 {
70 string sql_2 = "Insert into Lopdiem10 values('" + dt2.Rows[i][0] + "'," + dt2.Rows[i][1] + ")";
71 da.ExcuteNonQuery(sql_2);
72 }
73 //Table 3
74 string sql3 = " select Lopdiem10.MaSV,'TrungBinhCuoiKyHe10'=cuoiky/sotinchi " +
75 " from Lopdiem10 left join Loptc on Loptc.MaSV=Lopdiem10.MaSV";
76 DataTable dt3 = da.GetTable(sql3);
77 for (int i = 0; i < dt3.Rows.Count; i++)
78 {
79 string sql_3 = "Insert into DTB values('" + dt3.Rows[i][0] + "'," + dt3.Rows[i][1] + ")";
80 da.ExcuteNonQuery(sql_3);
81 }
82 }
File name: ClassBLL.cs
Copy
191 public int CheckLogin(string name, string pass)
192 {
193 SqlConnection con = da.GetConnect();
194 SqlCommand cmd = new SqlCommand("select *from Users Where Username='"+name+"' and Password='"+pass+"'",con);
195 con.Open();
196 SqlDataReader dr = cmd.ExecuteReader();
197 if (dr.Read())
198 {
199 if (dr[2].ToString() == "admin")
200 {
201 return 1;
202 }
203 else
204 {
205 return 2;
206 }
207 }
208 else
209 {
210 return -1;
211 }
212 }
File name: ClassBLL.cs
Copy
213 public string TinhDiemTB(string MaSV, string MaHK)
214 {
215 SqlConnection con = da.GetConnect();
216 con.Open();
217 //view tc
218 string sql1 = " select 'sotinchi'=sum(SoTC) " +
219 " from KetQua kq,HocPhan hp,NhomHocPhan nhp,KeHoachGiangDay khgd " +
220 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khgd.MaKHGD=nhp.MaKHGD and MaSV='"+MaSV+"' and MaHK='"+MaHK+"' " +
221 " group by MaSV ";
222 SqlCommand cmd1 = new SqlCommand(sql1, con);
223 string tc = cmd1.ExecuteScalar().ToString();
224 // view diem10
225 string sql2 = " select 'cuoiky'=sum(DiemTk10*SoTC) " +
226 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
227 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaSV='"+MaSV+"' and MaHK='"+MaHK+"' " +
228 " group by MaSV ";
229 SqlCommand cmd2 = new SqlCommand(sql2, con);
230 string diem10 = cmd2.ExecuteScalar().ToString();
231 //view diem4
232 string sql3 = " select 'cuoiky'=sum(DiemTk4*SoTC) " +
233 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
234 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaSV='"+MaSV+"' and MaHK='"+MaHK+"' " +
235 " group by MaSV ";
236 SqlCommand cmd3 = new SqlCommand(sql3, con);
237 string diem4 = cmd3.ExecuteScalar().ToString();
238
239
240 string ketqua="";
241 ketqua = Convert.ToDouble(diem10) / Convert.ToDouble(tc) + "," + Convert.ToDouble(diem4) / Convert.ToDouble(tc) ;
242 return ketqua;
243 }
File name: ClassBLL.cs
Copy
244 public string TinhDiemTB(string MaSV)
245 {
246 SqlConnection con = da.GetConnect();
247 con.Open();
248 //view tc
249 string sql1 = " select 'sotinchi'=sum(SoTC) " +
250 " from KetQua kq,HocPhan hp,NhomHocPhan nhp,KeHoachGiangDay khgd " +
251 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khgd.MaKHGD=nhp.MaKHGD and MaSV='" + MaSV + "'" +
252 " group by MaSV ";
253 SqlCommand cmd1 = new SqlCommand(sql1, con);
254 string tc = cmd1.ExecuteScalar().ToString();
255 // view diem10
256 string sql2 = " select 'cuoiky'=sum(DiemTk10*SoTC) " +
257 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
258 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaSV='" + MaSV + "'" +
259 " group by MaSV ";
260 SqlCommand cmd2 = new SqlCommand(sql2, con);
261 string diem10 = cmd2.ExecuteScalar().ToString();
262 //view diem4
263 string sql3 = " select 'cuoiky'=sum(DiemTk4*SoTC) " +
264 " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
265 " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaSV='" + MaSV + "'" +
266 " group by MaSV ";
267 SqlCommand cmd3 = new SqlCommand(sql3, con);
268 string diem4 = cmd3.ExecuteScalar().ToString();
269
270
271 string ketqua = "";
272 ketqua = Convert.ToDouble(diem10) / Convert.ToDouble(tc) + "," + Convert.ToDouble(diem4) / Convert.ToDouble(tc);
273 return ketqua;
274 }
File name: ClassBLL.cs
Copy
275 public bool Proc_Insert(string proc,string test)
276 {
277 SqlConnection con = da.GetConnect();
278 con.Open();
279 SqlCommand cmd = new SqlCommand(proc, con);
280 cmd.CommandType = CommandType.StoredProcedure;
281 cmd.Parameters.Add("@test", SqlDbType.NVarChar).Value = test;
282 SqlDataReader dr = cmd.ExecuteReader();
283 if (dr.Read())
284 {
285 return false;
286 }
287 return true;
288 }
File name: ClassBLL.cs
Copy
302 public void Insert(string table,string sql)
303 {
304 sql = "insert into "+table+" values("+sql+")";
305 da.ExcuteNonQuery(sql);
306 }
File name: crBaoCao.cs
Copy
33 public override bool NewGenerator {
34 get {
35 return true;
36 }
37 set {
38 // Do nothing
39 }
40 }
File name: crBaoCao.cs
Copy
145 public virtual string GetCustomizedCacheKey(RequestContext request) {
146 String key = null;
147 // // The following is the code used to generate the default
148 // // cache key for caching report jobs in the ASP.NET Cache.
149 // // Feel free to modify this code to suit your needs.
150 // // Returning key == null causes the default cache key to
151 // // be generated.
152 //
153 // key = RequestContext.BuildCompleteCacheKey(
154 // request,
155 // null, // sReportFilename
156 // this.GetType(),
157 // this.ShareDBLogonInfo );
158 return key;
159 }
File name: FormBaoCao.cs
Copy
40 private void btnLoc_Click(object sender, EventArgs e)
41 {
42 SqlConnection con = dal.GetConnect();
43 con.Open();
44 string sql = "select *from SinhVien where MaLop=@MaLop";
45 SqlDataAdapter da = new SqlDataAdapter(sql, con);
46 da.SelectCommand.Parameters.AddWithValue("@MaLop", cmbMaLop.SelectedValue.ToString());
47 DataTable dt = new DataTable();
48 da.Fill(dt);
49 crBaoCao cr = new crBaoCao();
50 ConnectionInfo crConnectionInfo = new ConnectionInfo();
51 crConnectionInfo.ServerName = "Ty-PC";
52 crConnectionInfo.DatabaseName = "CNPM_1";
53 crConnectionInfo.UserID = "sa";
54 crConnectionInfo.Password = "04091990";
55 TableLogOnInfos crTableLogonInfos = new TableLogOnInfos();
56 foreach (CrystalDecisions.CrystalReports.Engine.Table table in cr.Database.Tables)
57 {
58 TableLogOnInfo crTableLogonInfo = new TableLogOnInfo();
59 crTableLogonInfo.TableName = table.Name;
60 crTableLogonInfo.ConnectionInfo = crConnectionInfo;
61 crTableLogonInfos.Add(crTableLogonInfo);
62 table.ApplyLogOnInfo(crTableLogonInfo);
63
64 }
65 crvHocKyHocPhan.LogOnInfo = crTableLogonInfos;
66 cr.SetDataSource(dt);
67 ParameterValues a = new ParameterValues();
68 ParameterDiscreteValue b = new ParameterDiscreteValue();
69 b.Value = cmbMaLop.SelectedValue.ToString();
70 a.Add(b);
71 cr.DataDefinition.ParameterFields["txtMaLop"].ApplyCurrentValues(a);
72 crvHocKyHocPhan.ReportSource = cr;
73 crvHocKyHocPhan.Show();
74 }
Download file with original file name:To
To 141 lượt xem
Gõ tìm kiếm nhanh...