2

我想从 DataReader 中按列检索数据。

现在我这样使用,

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

有没有办法按列名获取数据?像

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

谢谢!

4

1 回答 1

8

你试过这个:

string columnA = Convert.ToString(reader["B"]);
于 2012-04-19T15:31:21.700 回答