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 DataSet deldata(string sortfield)
   {

    System.Data.OleDb.OleDbConnection conn = GetConnection();
    DataSet ds = new DataSet();

    try
    {

     int inc;
     int MaxRows;

     //Dim sql As String = "select * from table1"
     //Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, conn)

     try
     {

      string sqldelete = default(string);
      sqldelete = "DELETE * FROM table1 WHERE STUDENTID=\'" + Form1.Default.STUDID.Text + "\'";
      System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(sqldelete, conn);

      // Gets the records from the table and fills our adapter with those.
      DataTable dt = new DataTable("grade1");
      da.Fill(dt);
      MessageBox.Show("Data has been deleted");
      clearall();

      Form1.Default.DataGridView1.DataSource = dt;

      RefreshDGV();

     }
     finally
     {
      //da.Dispose()
     }

     return ds;
    }
    finally
    {
     conn.Close();
     conn.Dispose();
    }
   }