-
Simple db problem
Code:
OleDbConnection thisConnection = new OleDbConnection("provider = microsoft.jet.oledb.4.0;data source = people.mdb;");
OleDbCommand thisCommand = new OleDbCommand("SELECT ID FROM people",thisConnection);
thisConnection.Open();
OleDbDataReader thisReader = thisCommand.ExecuteReader();
Console.WriteLine("Product ID : {0}",
thisReader.GetValue(1));
Can anyone help with this??? I want to read values from a db, but I have this problem...It throws an invalid operation: no data exists for the row column.I have a db with only one column named id, with two fields containing 1 and 2. What should I put on the GetValue argument???
-
You have to call Read on the reader, once per row:
Code:
while(thisReader.Read())
{
object IndexedField = thisReader[0];
object NamedField = thisReader["NamedField"];
}
If you're sure there's just one row you could replace "while" with "if" instead.