private void GetUserFromDb() { Userlist.Clear(); int i = 0; var items = Userlist.Items; try { using (var con = new MySqlConnection(cs)) { con.Open(); var query = "SELECT systemName FROM users"; using (var cmd = new MySqlCommand(query, con)) { using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { items.Add(reader.GetString("SystemName")); Userlist.Items[i].ImageIndex = 0; i++; } } } } i++; } catch (MySqlException) { } }
private void RemoveUser_Click(object sender, EventArgs e) { try { MySqlConnection con = new MySqlConnection(cs); MySqlCommand cmd = con.CreateCommand(); cmd.CommandText = "DELETE FROM users where SystemName='" + Userlist.SelectedItems[0].Text + "' "; con.Open(); cmd.ExecuteNonQuery(); con.Close(); Userlist.Clear(); GetUserFromDb(); } catch (MySqlException) { } catch (Exception) { } }