Using C# & MySQL
When i select a particular value from the combobox then i clicked the button, the corresponding value should display in the other textbox
code
protected void Button1_Click(object sender, EventArgs e)
{
cmd2 = new OdbcCommand("Select name from users where username = '" + combobox1.Text + "' ", con);
dr1 = cmd2.ExecuteReader();
while (dr1.Read())
{
textbox1.Text = dr1.GetString(0);
}
dr1.Close();
}
The Above Code is working, but nothing displaying in Textbox1, there is the problem only in the query, I changed the query like Select name from users where username = '005'
Output is displaying in the textbox1, but when i used combobox value it is not displaying.
I also tried:
combobox1.text, combobox1.selectedvalue, combobox1.selecteditem, combobox1.selectedindex
Combobox Filling Code
cmd2 = new OdbcCommand("Select username from users, con);
ada2 = new OdbcDataAdapter(cmd2);
ada2.Fill(data2);
combobox1.DataValueField = "username";
combobox1.DataSource = data2;
combobox1.DataBind();
Username values like 201, 202, 203....,
Why is the query executing while using the combobox value....
Need Query Help