hi everyone, i'm new here also new in c#.Please help me to re-populate my listview in form1 from the database when i close form2(modal). is is from form2 formClosing event
private void Client_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = false;
ClientInfo a = new ClientInfo();
a.displayClient();//displayClient() is responsible for displaying //items from database
//also i called it during form1_Load()
a.Show();
}
Is there something wrong with my displayClient()? here it is from form1
public void displayClient()
{
dbClient db = new dbClient();
string con = db.Mycon();
MySqlConnection cnMySQL = new MySqlConnection(con);
cnMySQL.Open();
MySqlCommand cmdMySQL = cnMySQL.CreateCommand();
MySqlDataReader reader;
cmdMySQL.CommandText = "select * from CLIENT";
reader = cmdMySQL.ExecuteReader();
lvClient.Items.Clear();
MessageBox.Show("hi");
while (reader.Read())
{
int i = reader.FieldCount;
ListViewItem item1 = new ListViewItem(reader.GetString(0), i);
item1.SubItems.Add(reader.GetString(1));
item1.SubItems.Add(reader.GetString(2));
item1.SubItems.Add(reader.GetString(3));
item1.SubItems.Add(reader.GetString(4));
//Add the items to the ListView.
lvClient.Items.AddRange(new ListViewItem[] { item1 });
// Add the ListView to the control collection.
this.Controls.Add(lvClient);
i++;
}
cnMySQL.Close();
}
Please help.Thanks