Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error Occure on this line:-Label6.Text = reader[0];

Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)

what is mistake i cant understand....help me..
Posted
Updated 12-Jun-12 1:21am
v2
Comments
Vani Kulkarni 12-Jun-12 7:22am    
Please post your code.
[no name] 12-Jun-12 7:43am    
Hi,
Use this :
Label6.Text = reader[0].toString();
RDBurmon 13-Jun-12 9:34am    
Thanks Everyone who replied to this thread , So Member*********, I think you have got enough responses and you should be able to mark it as your answer and close the thread. Please do so.

You need to cast the reader value to string. You cannot directly assign reader value to label text.

It should be
C#
Label6.Text = reader.getValue(0);
 
Share this answer
 
You are missing the ToString(). It should be :

C#
Label6.Text = reader[0].ToString();
 
Share this answer
 
Label6.Text = reader[0].ToString()
 
Share this answer
 
You need to cast the value to a string like so:

C#
Label6.Text = Convert.ToString(reader[0]);


This way, if the object cannot be cast to a string, you will just get a null instead of having your method blow up (again).
 
Share this answer
 
Try this


SqlDataReader dr;
SqlCommand sqlcmddr = new SqlCommand("sqlquery, con);
C#
dr = sqlcmddr.ExecuteReader();
           if (drget.Read())
           {
Label6.Text = dr.GetValue(0).ToString();
}
 
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