DataReader, retrieve data by column


I want to retrieve data by column from DataReader.

Now I'm using like this,

AdsCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT a,b,c,d FROM testTable";
AdsDataReader reader = cmd.ExecuteReader();

string columnA = reader.GetValue(0).ToString(); // I want to use column name instead of index number

is there any way to get data by column name? like

string columnB = reader["B"].getValue(); 

Thank you!

Best Solution

Did you try this:

string columnA = Convert.ToString(reader["B"]);
Related Question