Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to give output in label after dropdownlist selected value query result.
but i get the output as---- System.Data.OleDb.OleDbDataReader ----

my code as follow

C#
protected void DDLWEEK7_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblfrmdt.Visible = true;
        lbltodt.Visible = true;
       
        OleDbConnection con = new OleDbConnection("Provider=MSDAORA;User ID=sd;password=321;Data Source=User");       
        OleDbCommand cmd3 = new OleDbCommand("SELECT d1  FROM VIPUL_DATE WHERE dw='" + DDLWEEK7.SelectedValue + "'", con);
        OleDbCommand cmd4 = new OleDbCommand("SELECT d2  FROM VIPUL_DATE WHERE dw='"+DDLWEEK7.SelectedValue+"'", con);
     
        con.Open();
     
        OleDbDataReader DR1= cmd3.ExecuteReader();
        OleDbDataReader DR2= cmd4.ExecuteReader();
       
        lblfrmdt.Text +=DR1;
        lbltodt.Text += DR2;
    }
Posted
Updated 27-Jul-11 23:26pm
v4

try to find out in the following way

C#
objReader = objCommand.ExecuteReader();
 while (objReader.Read())
{
 Label1.text += objReader["d1"].ToString();
}
 
Share this answer
 
v2
Comments
RaviRanjanKr 28-Jul-11 6:58am    
Nice Answer, My 5 :)
Dalek Dave 28-Jul-11 7:25am    
Good Call.
Mahendra.p25 28-Jul-11 8:13am    
Thanks
You're doing it wrong. You should have some sort of loop like this.

C#
while(DR1.Read())
{
   lblfrmdt.Text += DR1["d1"].ToString();
}

while(DR2.Read())
{
   lbltodt.Text += DR2["d2"].ToString();
}


Perhaps a little reading needs to be done. See the following for reference.
http://www.akadia.com/services/dotnet_data_reader.html[^]
http://msdn.microsoft.com/en-us/library/haa3afyz%28v=vs.71%29.aspx[^]
 
Share this answer
 
Comments
Dalek Dave 28-Jul-11 7:25am    
Nice, gets a 5.
walterhevedeich 28-Jul-11 19:42pm    
Thanks DD.
Just use like this
C#
while(DR1.Read())
{
   lblfrmdt.Text += DR1["d1"].ToString();
}
 
Share this answer
 
v5
You have to add following after ExecuteReader():
while(DR1.Read())
{
   lblfrmdt.Text += DR1[0].ToString();
}
while(DR2.Read())
{
   lbltodt.Text += DR2[0].ToString();
}

Then,
DR1.Close(); DR2.Close(); con.Close();

DataReader needs to call Read() function first so that, it can iterate through the Rows returned by ExecuteReader().
DataReader retrieves data row by row as Read() is called.
First call to Read() gets the First row returned. And so on...
So, we use while() condition so that data is retrieved as long as Read() is true and some data is present in DataReader.
And you're done!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900