I use SqlDataReader.GetValue method to read values from DB:
Log.WriteLine("Value of CompanyName column:" + thisReader.GetValue(1));
As parameter GetValue get index of column. How could I specify Column Name instead index?
string ColumnValue; if (dr["ColumnName"] != null) ColumnValue = dr["ColumnName"].
As explained earlier, the SqlDataReader returns data via a sequential stream. To read this data, you must pull data from a table row-by-row Once a row has been read, the previous row is no longer available.
ExecuteReader to retrieve rows from a data source. The DataReader provides an unbuffered stream of data that allows procedural logic to efficiently process results from a data source sequentially. The DataReader is a good choice when you're retrieving large amounts of data because the data is not cached in memory.
To create a SqlDataReader, you must call the ExecuteReader method of the SqlCommand object, instead of directly using a constructor. While the SqlDataReader is being used, the associated SqlConnection is busy serving the SqlDataReader, and no other operations can be performed on the SqlConnection other than closing it.
Log.WriteLine("Value of CompanyName column:" + thisReader["CompanyName"]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With