Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

         private void btnXem_Click(object sender, EventArgs e)
         {
             string sql1 = "select TenSV from SinhVien where MaSV='" + txtMaSV.Text + "'";
             if (business.ShowData_where(sql1).Rows.Count!=0)
             {
                 lblTenSV.Text= business.ShowData_where(sql1).Rows[0][0].ToString();
                 lblTenSV.Visible = true;
             }
             if (chbXemTatCaHocKy.Checked == true)
             {
                 string sql = "select HocPhan.MaHP,NhomHocPhan.MaNhomHP,HocPhan.TenHP,KetQua.DiemQT,KetQua.DiemThi,KetQua.DiemXepLoai " +
                                " From KetQua,HocPhan,NhomHocPhan,KeHoachGiangDay " +
                                 " Where KetQua.MaSV='" + txtMaSV.Text + "' " +
                                    " and KetQua.MaNhomHP=NhomHocPhan.MaNhomHP " +
                                    " and NhomHocPhan.MaHP=HocPhan.MaHP " +
                                    " and NhomHocPhan.MaKHGD=KeHoachGiangDay.MaKHGD ";
                 dgvKetQua.DataSource = business.ShowData_where(sql);
                 if (dgvKetQua.RowCount > 0)
                 {
                     string test = business.TinhDiemTB(txtMaSV.Text);
                     txtHe10.Text = test.Split(',')[0];
                     txtHe4.Text = test.Split(',')[1];
                 }
                 else
                 {
                     txtHe10.Text = "";
                     txtHe4.Text = "";
                 }
             }
             else
             {
                 string sql = "select HocPhan.MaHP,NhomHocPhan.MaNhomHP,HocPhan.TenHP,KetQua.DiemQT,KetQua.DiemThi,KetQua.DiemXepLoai " +
                                " From KetQua,HocPhan,NhomHocPhan,KeHoachGiangDay " +
                                 " Where KetQua.MaSV='" + txtMaSV.Text + "' " +
                                    " and KetQua.MaNhomHP=NhomHocPhan.MaNhomHP " +
                                    " and NhomHocPhan.MaHP=HocPhan.MaHP " +
                                    " and NhomHocPhan.MaKHGD=KeHoachGiangDay.MaKHGD " +
                                    " and KeHoachGiangDay.MaHK='" + cmbMaHK.SelectedValue.ToString() + "'";
                 dgvKetQua.DataSource = business.ShowData_where(sql);
                 if (dgvKetQua.RowCount > 0)
                 {
                     string test = business.TinhDiemTB(txtMaSV.Text, cmbMaHK.SelectedValue.ToString());
                     txtHe10.Text = test.Split(',')[0];
                     txtHe4.Text = test.Split(',')[1];
                 }
                 else
                 {
                     txtHe10.Text = "";
                     txtHe4.Text = "";
                 }
             }
         }