[英]How to get data by SqlDataReader.GetValue by column name
我使用SqlDataReader.GetValue方法從DB讀取值:
Log.WriteLine("Value of CompanyName column:" + thisReader.GetValue(1));
作為參數GetValue獲取列的索引。 我怎樣才能指定列名而不是索引?
Log.WriteLine("Value of CompanyName column:" + thisReader["CompanyName"]);
你也可以這樣做。
//find the index of the CompanyName column
int columnIndex = thisReader.GetOrdinal("CompanyName");
//Get the value of the column. Will throw if the value is null.
string companyName = thisReader.GetString(columnIndex);
thisReader.GetString(int columnIndex)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.