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 btbatdauthi_Click(object sender, EventArgs e)
         {
             try
             {
                 if (tbten.Text == "" || tbmathisinh.Text == "")
                 {
                     MessageBox.Show("Bạn phải điền đầy đủ thông tin");
                 }
                 else
                 {
                     string TenThSinh = tbten.Text;
                     string MaThiSinh = tbmathisinh.Text;
                     string strSQL = "insert THISINHTHI values('" + MaThiSinh + "','" + TenThSinh + "')";
                     SqlCommand ObjCmd = new SqlCommand(strSQL, ObjCon);
                     ObjCmd.ExecuteNonQuery();
                     if (MessageBox.Show("Bạn có chắc chắn thi không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                     {

                         string dienten = this.tbten.Text;//chuyen thong tin sang form thithat
                         string dienma = this.tbmathisinh.Text;
                         frmThiThat thithat = new frmThiThat(dienten, dienma);
                         thithat.ShowDialog();
                         this.Close();


                     }

                 }
             }
             catch
             {
                 MessageBox.Show("Mã thí sinh trùng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }

     }