I noticed in your code you have these: *conn.Close();*
*return** dr;* You've closed the connection then returned the "dr" (your datareader object) to the caller. Closing the connection killed the datareader as well. Using a DataSet would help you close the connection object but allows you to keep the records that you queried to the DataSet. So instead of using OleDbDataReader, why not use DataSet? I suggest you re-write the ExecuteReader() routine to use it. Cheers! Benj On Jan 2, 8:31 pm, Karthikeyan R <[email protected]> wrote: > 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
