Open
How do I use Open
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
195 | con.Open(); | 1 |
216 | con.Open(); | 2 |
247 | con.Open(); | 3 |
278 | con.Open(); | 4 |
28 | con.Open(); | 5 |
30 | con.Open(); | 6 |
43 | con.Open(); | 7 |
32 | con.Open(); | 8 |
30 | con.Open(); | 9 |
42 | con.Open(); | 10 |
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: ClassDAL.cs
Copy
25 public void ExcuteNonQuery(string sql)
26 {
27 SqlConnection con = GetConnect();
28 con.Open();
29 SqlCommand cmd = new SqlCommand(sql, con);
30 cmd.ExecuteNonQuery();
31 cmd.Dispose();
32 con.Close();
33 }
File name: FormBaoCao.cs
Copy
27 public void loadCmb()
28 {
29 SqlConnection con = dal.GetConnect();
30 con.Open();
31 SqlCommand cm = new SqlCommand("Select *from Lop", con);
32 SqlDataAdapter da = new SqlDataAdapter(cm);
33 DataTable dt = new DataTable();
34 da.Fill(dt);
35 this.cmbMaLop.DisplayMember = "MaLop";
36 this.cmbMaLop.ValueMember = "MaLop";
37 this.cmbMaLop.DataSource = dt;
38 }
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 }
File name: FormQuanLyDiem.cs
Copy
29 public void loadCmbMaNhomHP(string MaHK)
30 {
31 SqlConnection con = dal.GetConnect();
32 con.Open();
33 SqlCommand cm = new SqlCommand("Select MaNhomHP from NhomHocPhan,KeHoachGiangDay where NhomHocPhan.MaKHGD=KeHoachGiangDay.MaKHGD and KeHoachGiangDay.MaHK='"+MaHK+"'", con);
34 SqlDataAdapter da = new SqlDataAdapter(cm);
35 DataTable dt = new DataTable();
36 da.Fill(dt);
37 this.cmbMaNhomHP.DisplayMember = "MaNhomHP";
38 this.cmbMaNhomHP.ValueMember = "MaNhomHP";
39 this.cmbMaNhomHP.DataSource = dt;
40 }
File name: FormThongKe.cs
Copy
27 public void loadCmbLop()
28 {
29 SqlConnection con = dal.GetConnect();
30 con.Open();
31 SqlCommand cm = new SqlCommand("Select *from Lop", con);
32 SqlDataAdapter da = new SqlDataAdapter(cm);
33 DataTable dt = new DataTable();
34 da.Fill(dt);
35 this.cmbMa.DisplayMember = "MaLop";
36 this.cmbMa.ValueMember = "MaLop";
37 this.cmbMa.DataSource = dt;
38 }
File name: FormThongKe.cs
Copy
39 public void loadCmbKhoiLop()
40 {
41 SqlConnection con = dal.GetConnect();
42 con.Open();
43 SqlCommand cm = new SqlCommand("Select *from KhoiLop", con);
44 SqlDataAdapter da = new SqlDataAdapter(cm);
45 DataTable dt = new DataTable();
46 da.Fill(dt);
47 this.cmbMa.DisplayMember = "MaKhoiLop";
48 this.cmbMa.ValueMember = "MaKhoiLop";
49 this.cmbMa.DataSource = dt;
50 }
Download file with original file name:Open
Open 103 lượt xem
Gõ tìm kiếm nhanh...