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 timkiemtheongay()
         {
             if (tbngaythang.Text == "")
             {
                 rdb1.Checked = false;
                 MessageBox.Show("Bạn điền ngày tháng năm vao trước, theo dạng tháng / ngày / năm", "Có lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 tbngaythang.Enabled = true;
             }
             else
             {

                 Sngay = tbngaythang.Text;
                 try
                 {


                         sqlcmd = new SqlCommand("select thisinhthi.mats,HOTEN,NGAYTHI,SOCAUDUNG,SOCAUSAI,DIEM FROM THISINHTHI,KETQUA WHERE THISINHTHI.MATS=KETQUA.MATS and ngaythi='" + Sngay + "'", sqlcon);
                         SqlDataReader sqlreader = sqlcmd.ExecuteReader();
                         listView1.Items.Clear();
                         while (sqlreader.Read())
                         {
                             ListViewItem lvitem = new ListViewItem();
                             lvitem.Text = sqlreader["MATS"].ToString();
                             lvitem.SubItems.Add(sqlreader["HOTEN"].ToString().Trim());
                             lvitem.SubItems.Add(sqlreader["NGAYTHI"].ToString().Trim());
                             lvitem.SubItems.Add(sqlreader["SOCAUDUNG"].ToString().Trim());
                             lvitem.SubItems.Add(sqlreader["SOCAUSAI"].ToString().Trim());
                             lvitem.SubItems.Add(sqlreader["DIEM"].ToString().Trim());
                             listView1.Items.Add(lvitem);
                         }
                         sqlreader.Close();

                 }
                 catch
                 {
                     MessageBox.Show("Không có ai thi ngày này '" + Sngay + "'");
                     tbngaythang.Text = "";


                 }
             }
         }