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 editToolStripMenuItem_Click(object sender, EventArgs e) {
             try {
                 string eid = lvStudents.FocusedItem.SubItems[0].Text;

                 frmStudent fs = new frmStudent(eid);
                 if (fs.ShowDialog() == DialogResult.OK) {
                     loadStudents();
                 }
             } catch {}
         }

         private void refreshToolStripMenuItem_Click(object sender, EventArgs e) {
             loadStudents();
             showAll(cmbAdviser, "Adviser");
             showAll(cmbCurriculum, "Curriculum");
             showAll(cmbLevel, "SLevel");
             showAll(cmbSchoolYear, "SchoolYear");
             showAll(cmbSection, "SSection");
         }

         private void frmClass_Load(object sender, EventArgs e) {
             if (edit) {
                 OleDbConnection con = new OleDbConnection(conString);
                 OleDbCommand cmd;
                 OleDbDataAdapter da;
                 DataTable dt;

                 cmd = new OleDbCommand("SELECT * FROM tblStudent WHERE id=" + aid + ";", con);
                 da = new OleDbDataAdapter(cmd);
                 dt = new DataTable();
                 da.Fill(dt);

                 if (dt.Rows.Count > 0) {
                     cmbCurriculum.Text = dt.Rows[0][6].ToString();
                     cmbSchoolYear.Text = dt.Rows[0][7].ToString();
                     cmbLevel.Text = dt.Rows[0][8].ToString();
                     cmbSection.Text = dt.Rows[0][9].ToString();
                     cmbAdviser.Text = dt.Rows[0][10].ToString();
                     loadStudents();
                 }
             }
         }
     }