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(); } } }
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(); } }
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++; } }); }