I use SqlDataReader.GetValue method to read values from DB:
Log.WriteLine("Value of CompanyName column:" + thisReader.GetValue(1));
As parameter GetValue get index of column. How could I specify Column Name instead index?
Log.WriteLine("Value of CompanyName column:" + thisReader["CompanyName"]);
Log.WriteLine("Value of CompanyName column:" + thisReader.GetValue(thisReader.GetOrdinal("CompanyName"))); What [] means?return GetValue(GetOrdinal(name)); reference referencesource.microsoft.com/#system.data/system/data/…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);
thisReader.GetString(int columnIndex)