I'm new to c#
and I've using xampp
for mysql
connection with visual studio.
I'm trying to View list box selected item data that is connected to sql database table to text field when the item is clicked.
I'm using this code but nothing happens when i click the item..
private void listbox_user_SelectedIndexChanged(object sender, EventArgs e)
{
MySqlConnection sqlcon = new MySqlConnection("Server=localhost;Database=table1;Uid='root';Pwd='';SslMode=none");
sqlcon.Open();
MySqlCommand cmd = sqlcon.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM login WHERE Name='"+listbox_user.SelectedItem.ToString()+"'";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
foreach(DataRow dr in dt.Rows)
{
txtbox_name.Text = dr["Name"].ToString();
txtbox_username.Text = dr["Username"].ToString();
txtbox_pwd.Text = dr["Password"].ToString();
}
sqlcon.Close();
}
The database is connected and the data is there but nothing happens