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 button4_Click(object sender, EventArgs e)
         {
             if (richTextBox1.Text == "" || textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || (checkBox1.Checked == false && checkBox2.Checked == false && checkBox3.Checked == false && checkBox4.Checked == false))
             {
                 MessageBox.Show("Bạn chưa thêm đầy đủ thông tin", "Thông báo");
             }
             else
             {
                 try
                 {

                     string sCauA = textBox1.Text;
                     string sCauB = textBox2.Text;
                     string sCauC = textBox3.Text;
                     string sCauD = textBox4.Text;
                     string sMaCH = textBox5.Text;
                     string sCauHoi = richTextBox1.Text;
                     string sCauDung = "";
                     string sCauDungLuu = "";
                     string sTrinhDo = comboBox1.Text;
                     if (checkBox1.Checked == true)
                     {
                         sCauDung = "A";
                         sCauDungLuu += sCauDung;
                     }
                     if (checkBox2.Checked == true)
                     {
                         sCauDung = "B";
                         sCauDungLuu += sCauDung;
                     }
                     if (checkBox3.Checked == true)
                     {
                         sCauDung = "C";
                         sCauDungLuu += sCauDung;
                     }
                     if (checkBox4.Checked == true)
                     {
                         sCauDung = "D";
                         sCauDungLuu += sCauDung;
                     }

                     sqlcmd = new SqlCommand("insert into dapan values('" + sMaCH + "','" + sCauA + "','" + sCauB + "','" + sCauC + "','" + sCauD + "','" + sCauDungLuu + "') ", sqlcon);
                     sqlcmd.ExecuteNonQuery();
                     sqlcmd = new SqlCommand("insert into cauhoi values('" + sMaCH + "','" + sCauHoi + "','" + sTrinhDo + "') ", sqlcon);
                     sqlcmd.ExecuteNonQuery();
                     LoadDataToListView();
                     button4.Enabled = false;
                 }
                 //roi hen;de bi coi lai thu de cHOAky thu chay thu hen ok
                 catch
                 {
                     MessageBox.Show("Bạn đã thao tác sai");
                 }
             }
         }