"*// Try this one Karthik*
*
*
*return dr;*
*then close connection;
*
** "


Hi.

I think if you do this, you'll get a compiler error/
warning:"Unreachable code detected.".
As far as I can tell, any statement below the return statement
produces this
error/warning except when you program in Borland Delphi. ;)



Cheers!



Benj







On Jan 4, 8:45 am, sushma sushma <[email protected]> wrote:
> *
> Check the red marked code karthikeya.
>
> OleDbDataReader ExecuteReader(string** ReaderQuery)*
>
> *{*
>
> *cmd =*
> *new OleDbCommand**(ReaderQuery, conn);*
>
> *conn.Open();*
>
> *dr = cmd.ExecuteReader(*
> *CommandBehavior**.CloseConnection);*
> *
> *
> *// Try this one Karthik*
> *
> *
> *return dr;*
> *then close connection;
> *
> **
>
> *conn.Close();*
>
> *return** dr;*
>
>
>
> On Sat, Jan 2, 2010 at 7:31 AM, 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
>
> --
> Thanks,
>
> Sushma
>
> Email: [email protected]

Reply via email to