Hi,
I am getting *"Invalid attempt to Read when reader is closed"* error in one
of my pages.I have used the following method in my class file,
public class ExecuteQuery
{
OleDbConnection conn;
OleDbCommand cmd;
DataTable dt;
OleDbDataAdapter da;
OleDbDataReader dr;
public ExecuteQuery()
{
conn = new OleDbConnection();
conn.ConnectionString = DBConnection.GetConnectionString();
}
*public** OleDbDataReader ExecuteReader(string** ReaderQuery)*
*{ *
*cmd = **new OleDbCommand**(ReaderQuery, conn); *
*conn.Open();*
*dr = cmd.ExecuteReader(**CommandBehavior**.CloseConnection); *
*conn.Close();*
*return** dr;*
*}*
}
In the aspx.cs file I have used the following code,
private void ddlfill()
{
try
{
ddlquestion.Items.Add("");
ddlquestion.SelectedIndex = 0;
string query = "select Hint_Question from Tbl_Hintquestion order by Hint_No
ASC";
bool abc = EQuery.ExecuteReader(query).Read();
while (abc == true)
{
ddlquestion.Items.Add(dr["Hint_Question"].ToString());
abc = EQuery.ExecuteReader(query).Read();
}
}
catch (Exception EXE)
{
Alert.Show(EXE.Message);
}
}
Can some one help me out to solve this problem?
--
Thanks & Regards,
Karthikeyan