我尝试从列表框选择c#中填充来自mysql数据库的3个文本框。
当我加载页面并单击查询按钮时,它会填充列表框,然后当我在列表框中选择另一个值时,它会自动查询以填充文本框,但根本不填写它们。
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string selectedperson = listBox1.GetItemText(listBox1.SelectedItem);
string query = "Select * from `clients`
WHERE 'client_nickname'='" + selectedperson + "'";
MySqlConnection conn2 = new MySqlConnection("datasource =" +
Properties.Settings.Default.Hostname + " ;
username = " + Properties.Settings.Default.Username + ";
password = " + Properties.Settings.Default.Password + ";
port = " + Properties.Settings.Default.Port + ";
database = " + Properties.Settings.Default.Database);
conn2.Open();
DataSet ds = new DataSet();
MySqlDataAdapter da = new MySqlDataAdapter(query, conn2);
if (ds.Tables.Count > 0)
{
da.Fill(ds);
textBox1.Text = ds.Tables[8].Rows[2]["client_unique_id"].ToString();
textBox2.Text = ds.Tables[8].Rows[4]["client_login_name"].ToString();
textBox3.Text = ds.Tables[8].Rows[5]["client_login_password"].ToString();
}
}