I am having a bit of trouble with a try..catch..finally block I am writing. When I get to my finally block, the compiler is complaining that it can't find my reader. It doesn't make much sense to me that a variable is the try block would be out of scope in the finally block.
Code:
private Question RetrieveQuestion(string testID)
{
try
{
//Retrieve test questions from the database
string sqlQues = "SELECT Tests.Test_ID, Test_Questions.Question_Num, [Test_Questions.Text], " +
"Test_Questions.Graphic_Path" +
"FROM Tests, Test_Questions" +
"WHERE Tests.Test_ID = Test_Questions.Test_ID AND Test_Questions.Test_ID = '" + testID + "' " +
"ORDER BY Test_Questions.Question_Num";
OleDbCommand getQues = new OleDbCommand(sqlQues, aLib.SQLConnection);
OleDbDataReader readQues = getQues.ExecuteReader();
while(readQues.Read())
{
Question tempQues = new Question();
tempQues.Text = readQues.GetString(2);
tempQues.SetGraphic(readQues.GetString(3),"administrator","sthstrn");
tempTest.AddQuestion(tempQues);
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
finally
{
readQues.Close();
}
}