Adding a column value by using DataReader
Using C# & MySQL
When I select the combobox value, the corresponding value should display in textbo开发者_开发技巧x
C# Code.
cmd2 = new OdbcCommand("Select name from users where username='" + cmbuser.Text + "'", con);
dr= cmd2.ExecuteReader();
while (dr.Read())
{
txtusername.Text = dr("user");
}
The Above code is working in VB.Net, but in C# showing error as Error "dr' is a 'field' but is used like a 'method' "
It is showing error in this line txtusername.Text = dr("user");
How to solve this error, what problem in my code.
Need C# Code Help
Use the rectangular brackets in c#:
txtusername.Text = dr["user"];
Edit: You have to cast the object to the desired type after.
May be you need to use txtusername.Text = dr.GetString(0);
instead of your error line...
精彩评论