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 btnthem_Click(object sender, EventArgs e)
         {
             try
             {
             string mats = textBox1.Text;
             string hoten = textBox2.Text;
             string ngaysinh = textBox3.Text;
             string gioitinh = textBox4.Text;
             string quequan = textBox5.Text;
             string sodt = textBox6.Text;
             string email = textBox7.Text;

             string strSQL = "insert SINHVIEN values('" + mats + "','" + hoten + "','" + ngaysinh + "','" + gioitinh + "','" + quequan + "','" + sodt + "','" + email + "')";
             sqlcmd = new SqlCommand(strSQL, sqlcon);
             sqlcmd.ExecuteNonQuery();
             MessageBox.Show("B?n dã dang ký thành công");
             load();
             }
                 catch
             {
                 MessageBox.Show("Trùng mã sinh viên !!!");
                 }

         }