Using OleDb to find a column with a given name
Posted on 2006-07-13
I am designing for an SQL Server database, but was provided an Access mock up because the SQL Server database is not yet done. So I need to make my code as transportable as possible.
How do I "request" the column name from an OleDbReader? Or is there some other way to get the data from the first column, for example, without already knowing that the ID is stored in the first column. In this example, the first column is called "ID".
int id = reader.GetInt32(0);
This capability would allow me to switch to the SQL Server version more easily, since I expect the columns to be in a different order.