Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data by SqlDataReader.GetValue by column name

Tags:

c#

sql

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?

like image 287
algot Avatar asked Dec 28 '11 12:12

algot


People also ask

How do I check if a DataReader has a column?

string ColumnValue; if (dr["ColumnName"] != null) ColumnValue = dr["ColumnName"].

What does SqlDataReader return?

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.

Which function of DataReader is used to get the data from it?

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.

Which method provides SqlDataReader object from SqlCommand object?

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.


1 Answers

Log.WriteLine("Value of CompanyName column:" + thisReader["CompanyName"]);  
like image 88
Mauricio Scheffer Avatar answered Sep 28 '22 00:09

Mauricio Scheffer