ToString
How do I use To String
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
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: 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: FormGiangVien.cs
Copy
31 private void dgvGiangVien_RowEnter(object sender, DataGridViewCellEventArgs e)
32 {
33 dong = e.RowIndex;
34 txtMaGV.Text = dgvGiangVien.Rows[dong].Cells[0].Value.ToString();
35 txtTenGV.Text = dgvGiangVien.Rows[dong].Cells[1].Value.ToString();
36 dtpNamSinh.Text = dgvGiangVien.Rows[dong].Cells[2].Value.ToString();
37 txtDiaChi.Text = dgvGiangVien.Rows[dong].Cells[3].Value.ToString();
38 }
File name: FormHeDaoTao.cs
Copy
30 private void dgvHeDaoTao_RowEnter(object sender, DataGridViewCellEventArgs e)
31 {
32 dong = e.RowIndex;
33 txtMaHeDT.Text = dgvHeDaoTao.Rows[dong].Cells[0].Value.ToString();
34 txtTenHeDT.Text = dgvHeDaoTao.Rows[dong].Cells[1].Value.ToString();
35 }
File name: FormHocKy.cs
Copy
30 private void dgvHocKy_RowEnter(object sender, DataGridViewCellEventArgs e)
31 {
32 dong = e.RowIndex;
33 txtMaHocKy.Text = dgvHocKy.Rows[dong].Cells[0].Value.ToString();
34 txtTenHocKy.Text = dgvHocKy.Rows[dong].Cells[1].Value.ToString();
35 txtNamHoc.Text = dgvHocKy.Rows[dong].Cells[2].Value.ToString();
36 dtpBatDau.Text = dgvHocKy.Rows[dong].Cells[3].Value.ToString();
37 dtpKetThuc.Text = dgvHocKy.Rows[dong].Cells[4].Value.ToString();
38 }
File name: FormHocPhan.cs
Copy
65 private void dgvHocPhan_RowEnter(object sender, DataGridViewCellEventArgs e)
66 {
67 dong = e.RowIndex;
68 txtMaHP.Text = dgvHocPhan.Rows[dong].Cells[0].Value.ToString();
69 txtTenHP.Text = dgvHocPhan.Rows[dong].Cells[1].Value.ToString();
70 txtSoTC.Text = dgvHocPhan.Rows[dong].Cells[2].Value.ToString();
71 txtSoTietTH.Text=dgvHocPhan.Rows[dong].Cells[3].Value.ToString();
72 txtSoTietLT.Text = dgvHocPhan.Rows[dong].Cells[4].Value.ToString();
73 txtPhanTramDQT.Text = dgvHocPhan.Rows[dong].Cells[5].Value.ToString();
74 txtPhanTramDT.Text = dgvHocPhan.Rows[dong].Cells[6].Value.ToString();
75 }
File name: FormKHGD.cs
Copy
34 private void btnThem_Click(object sender, EventArgs e)
35 {
36 if (txtMaKHGD.Text != "")
37 {
38 if (business.Proc_Insert("Insert_KHGD",txtMaKHGD.Text))
39 {
40 string sql = "'"+txtMaKHGD.Text+"','"+cmbMahocKy.SelectedValue.ToString()+"','"+cmbMaKhoiLop.SelectedValue.ToString()+"'";
41 business.Insert("KeHoachGiangDay",sql);
42 FormKHGD_Load(sender, e);
43 }
44 else
45 {
46 MessageBox.Show("Mã KHGD đã tồn tại rồi");
47 }
48 }
49 }
File name: FormKHGD.cs
Copy
63 private void btnSua_Click(object sender, EventArgs e)
64 {
65 string sql = "MaHK='"+cmbMahocKy.SelectedValue.ToString()+"',MaKhoiLop='"+cmbMaKhoiLop.SelectedValue.ToString()+"' where MaKHGD='"+txtMaKHGD.Text+"'";
66 business.Update("KeHoachGiangDay",sql);
67 FormKHGD_Load(sender, e);
68 }
ToString 129 lượt xem
Gõ tìm kiếm nhanh...