Exemple #1
0
    private void GetData(string fetch, ReaderCallback readCallback)
    {
        SqlDataReader reader  = null;
        SqlCommand    command = null;
        int           counter = 1;

        try
        {
            connection.Open();
            command            = new SqlCommand(fetch);
            command.Connection = connection;
            reader             = command.ExecuteReader();
            readCallback.Invoke(reader, counter); // callback to handle the record
        }
        catch (Exception ex)
        {
            SQL_msg.ShowMessageBox(ex.Message);
        }
        finally
        {
            if (reader != null)
            {
                reader.Close();
            }
            if (connection.State == ConnectionState.Open)
            {
                connection.Close();
            }
        }
    }
Exemple #2
0
 private void GetData(string fetch, ReaderCallback readCallback)
 {
     SqlDataReader reader = null;
     SqlCommand command = null;
     int counter = 1;
     try
     {
         connection.Open();
         command = new SqlCommand(fetch);
         command.Connection = connection;
         reader = command.ExecuteReader();
         readCallback.Invoke(reader, counter); // callback to handle the record
     }
     catch (Exception ex)
     {
         SQL_msg.ShowMessageBox(ex.Message);
     }
     finally
     {
         if (reader != null)
             reader.Close();
         if (connection.State == ConnectionState.Open)
             connection.Close();
     }
 }
Exemple #3
0
 private void GetData_ByRecord(string fetch, ReaderCallback readCallback)
 {
     GetData(fetch,
             (reader, counter) => {
         while (reader.Read())
         {
             readCallback.Invoke(reader, counter);     // callback to handle the record
             counter++;
         }
     });
 }
Exemple #4
0
 private void GetData_ByRecord(string fetch, ReaderCallback readCallback)
 {
     GetData(fetch, 
         (reader, counter) => {
             while (reader.Read())
             {
                 readCallback.Invoke(reader, counter); // callback to handle the record
                 counter++;
             }
         });
 }