Note that there are some explanatory texts on larger screens.

plurals
  1. POrefresh datagridview from another form
    text
    copied!<p>i have two form. main form and child form. in main form show datagridview and in child form is a form to insert data to datagridview in main form.. so after i insert data from child form i want to refresh the datagridview in main form. so the new data appear in datagridview. i tried this code, but the datagridview not refresh, i must close my application and reopen it to show the new datagridview...</p> <pre><code>public void button1_Click(object sender, EventArgs e) { string cstr = "server=localhost;User Id=root;database=sma9"; con1 = new MySqlConnection(cstr); con1.Open(); com1 = new MySqlCommand(); com1.Connection = con1; com1.CommandType = CommandType.Text; com1.CommandText = "INSERT INTO tbukux (kodebuku,judulbuku,namakategori,pengarang,penerbit,tahunterbit,stokbuku) VALUES ('" + txtkode.Text + "','" + txtjudul.Text + "','" + txtkategori.Text + "','" + txtpengarang.Text + "','" + txtpenerbit.Text + "','" + txttahun.Text + "','" + txtstok.Text + "')"; com1.ExecuteNonQuery(); con1.Close(); Form1 form1 = new Form1(); form1.gridbuku.RefreshEdit(); } </code></pre> <p>i also tried this, but not working too</p> <pre><code>public void button1_Click(object sender, EventArgs e) { Form1 form1 = new Form1(); string cstr = "server=localhost;User Id=root;database=sma9"; con1 = new MySqlConnection(cstr); con1.Open(); com1 = new MySqlCommand(); com1.Connection = con1; com1.CommandType = CommandType.Text; com1.CommandText = "INSERT INTO tbukux (kodebuku,judulbuku,namakategori,pengarang,penerbit,tahunterbit,stokbuku) VALUES ('" + txtkode.Text + "','" + txtjudul.Text + "','" + txtkategori.Text + "','" + txtpengarang.Text + "','" + txtpenerbit.Text + "','" + txttahun.Text + "','" + txtstok.Text + "')"; com1.ExecuteNonQuery(); com2 = new MySqlCommand(); com2.Connection = con1; com2.CommandType = CommandType.Text; com2.CommandText = "select * from tbukux"; ds1 = new DataSet(); adp1 = new MySqlDataAdapter(com2); adp1.Fill(ds1, "tbukux"); form1.gridbuku.DataSource = ds1; form1.gridbuku.DataMember = "tbukux"; con1.Close(); form1.gridbuku.Refresh(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload