Hi all, I am developing a windows application.In that one form contains multiple datagridivew which displays the table content from mysql table. In form i have button which links to another windows form and their i am inserting values to the table. After inserting when i click on Save button, it should save in the table and also updates in the datagridview.
If i call the display() method after inserting values to the table, it is displaying N number of times.
public void display()
{
try
{
connection = new MySqlConnection(connection_string);
connection.Open();
dataAdapter_Customer=new MySqlDataAdapter(string.Format("select cusname,balance, contact, phone1,email from new_customer where busname=?p1"),connection);
dataAdapter_Customer.SelectCommand.Parameters.AddWithValue("?p1", busnamevar);
commandBuilder_Customer=new MySqlCommandBuilder(dataAdapter_Customer);
dataTable_Customer.Locale=System.Globalization.CultureInfo.InvariantCulture;
dataAdapter_Customer.Fill(dataTable_Customer);
bindingSource=new BindingSource();
bindingSource.DataSource=dataTable_Customer;
dataGridView1.DataSource=bindingSource;
dataAdapter_Supplier = new MySqlDataAdapter(string.Format("select suppliername,total_balance,contact,phone1,email from new_supplier where businessname=?p1"), connection);
dataAdapter_Supplier.SelectCommand.Parameters.AddWithValue("?p1", busnamevar);
commandBuilder_Supplier = new MySqlCommandBuilder(dataAdapter_Supplier);
dataTable_Customer.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter_Supplier.Fill(dataTable_Supplier);
bindingSource1 = new BindingSource();
bindingSource1.DataSource = dataTable_Supplier;
dataGridView3.DataSource = bindingSource1;
connection.Close();
}
catch(MySqlException ex)
{
MessageBox.Show(ex.ToString());
}
}
If the table contains 4 rows, when i call display() method, it is showing 8 rows, like that it is increasing when ever i click on refresh button.
I think i have to clean after displaying the contents.