DataReader, retrieve data by column

advantage-database-serverasp.netdatareader

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

reader.Read();
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 Answer

Did you try this:

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