tags:

views:

35

answers:

2

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

+3  A: 

Use the rectangular brackets in c#:

txtusername.Text = dr["user"];

Edit: You have to cast the object to the desired type after.

Fabian
this will return type `object`
Marc
+2  A: 

May be you need to use txtusername.Text = dr.GetString(0); instead of your error line...

SKINDER