I am trying to to retrieve a value from a table called Session_ID. When the line in my try block is executed, I get a "Row handle is invalid" error. The value I am trying to get is a long integer in an Access database. I have also tried a SELECT MAX and it still doesn't work. You guys have any helpful suggestions?
Code:
private int GetSessionNumber()
{
//Check database connection. If closed, open it
if (aLib.SQLConnection.State==System.Data.ConnectionState.Closed)
aLib.SQLConnection.Open();
string sql = "SELECT Session_ID FROM User_Tests " +
"WHERE Test_ID = '" + testID + "' AND User_ID = '" + taker.UserID + "' " +
"ORDER BY Session_ID DESC";
OleDbCommand getSession = new OleDbCommand(sql,aLib.SQLConnection);
OleDbDataReader sessionReader = getSession.ExecuteReader();
sessionReader.Read();
//MessageBox.Show(Convert.ToString((int)sessionReader.GetValue(0)));
try
{
int sessionID = sessionReader.GetInt32(0);
}
catch(Exception e) { MessageBox.Show(e.ToString()); }
sessionReader.Close();
//return(sessionID);
return 0;
}