我使用SqlDataReader.GetValue方法从DB读取值:
Log.WriteLine("Value of CompanyName column:" + thisReader.GetValue(1));
Run Code Online (Sandbox Code Playgroud)
作为参数GetValue获取列的索引.我怎样才能指定列名而不是索引?
Mau*_*fer 83
Log.WriteLine("Value of CompanyName column:" + thisReader["CompanyName"]);
Run Code Online (Sandbox Code Playgroud)
Ray*_*Ray 52
你也可以这样做.
//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);
Run Code Online (Sandbox Code Playgroud)