Using C# & MySQL
When I select the combobox value, the corresponding value should display in textbox
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With