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:

         public void ChuanBi3Table(string MaHK)
         {
             //Table 1
             string sql1 = " select MaSV,'sotinchi'=sum(SoTC) " +
                        " from KetQua kq,HocPhan hp,NhomHocPhan nhp,KeHoachGiangDay khgd " +
                        " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khgd.MaKHGD=nhp.MaKHGD and MaHK='" + MaHK + "' " +
                        " group by MaSV ";
             DataTable dt1 = da.GetTable(sql1);
             for (int i = 0; i < dt1.Rows.Count; i++)
             {
                 string sql_1 = "Insert into Loptc values('" + dt1.Rows[i][0] + "'," + dt1.Rows[i][1] + ")";
                 da.ExcuteNonQuery(sql_1);
             }
             //Table 2
             string sql2 = "select MaSV,'cuoiky'=sum(DiemTk10*SoTC) " +
                            " from KetQua kq,NhomHocPhan nhp,HocPhan hp,KeHoachGiangDay khdt " +
                            " where kq.MaNhomHP=nhp.MaNhomHP and nhp.MaHP=hp.MaHP and khdt.MaKHGD=nhp.MaKHGD and MaHK='" + MaHK + "' " +
                            " group by MaSV ";
             DataTable dt2 = da.GetTable(sql2);
             for (int i = 0; i < dt2.Rows.Count; i++)
             {
                 string sql_2 = "Insert into Lopdiem10 values('" + dt2.Rows[i][0] + "'," + dt2.Rows[i][1] + ")";
                 da.ExcuteNonQuery(sql_2);
             }
             //Table 3
             string sql3 = " select Lopdiem10.MaSV,'TrungBinhCuoiKyHe10'=cuoiky/sotinchi " +
                            " from Lopdiem10 left join Loptc on Loptc.MaSV=Lopdiem10.MaSV";
             DataTable dt3 = da.GetTable(sql3);
             for (int i = 0; i < dt3.Rows.Count; i++)
             {
                 string sql_3 = "Insert into DTB values('" + dt3.Rows[i][0] + "'," + dt3.Rows[i][1] + ")";
                 da.ExcuteNonQuery(sql_3);
             }
         }