algot algot - 1 month ago 11
C# Question

How to get data by SqlDataReader.GetValue by column name

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?

Answer
Log.WriteLine("Value of CompanyName column:" + thisReader["CompanyName"]);