How to get data by SqlDataReader.GetValue by column name

后端 未结 3 760
野趣味
野趣味 2020-12-05 12:34

I use SqlDataReader.GetValue method to read values from DB:

Log.WriteLine(\"Value of CompanyName column:\" + thisReader.GetValue(1)); 

As p

3条回答
  •  情歌与酒
    2020-12-05 13:26

    You can also do this.

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

提交回复
热议问题