Datareader doubt...();

Feb 18 2006 8:21 AM

Hi,

I am trying to populate some text box controls from my database where in i have 4 rows with six coulmns.

Please see the code below. I am able to see two of rows data when I press the button but it doesn't go to 3rd and 4th row. Please suggest me how i could make it possible

Let me know should you require more info.

Thanks,
Bhushan. ( Member ).


  SqlDataReader dr;
  SqlCommand dbCommand;
  SqlConnection con;
  private void Page_Load(object sender, System.EventArgs e)
  {
   string command;
   con=new SqlConnection("server=HOME;database=myDatabase;Trusted_Connection=Yes");
   command="Select * from Orders";
   dbCommand=new SqlCommand(command,con);
   con.Open();
   dr=dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
   if(!dr.HasRows)
    Response.Write("no rows");
   else
   {
    recall();
   }
   
  }


  public void Button1_Click(object sender, System.EventArgs e)
  {
   if(!dr.HasRows)
    Response.Write("no rows");
   else
   {
    recall();
   }
  }


  public void recall()
  {
   dr.Read();
   ordid.Text=dr["orderid"].ToString();
   cname.Text=dr["customername"].ToString();
   pnum.Text=dr["productnumber"].ToString();
   pname.Text=dr["productname"].ToString();
   qty.Text=dr["quantity"].ToString();
   orddt.Text=dr["orderdate"].ToString();
  }


Answers (1)