Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to update rows list of a datagridview after adding new row to a table
    primarykey
    data
    text
    <p>I have a datagridview filled with a table collection on the load event of the form, i have also a form filled by the user and that add new row to the table onclick event, i would like to update the datagridview after adding new row to the table, i use a sqladapter binded to a bindingdatasource. this is the code </p> <pre><code> private void button1_Click(object sender, EventArgs e) { connection.Open(); string nv = textBox7.Text.Trim().Replace(',', '.'); // string sql=""; sql = "INSERT INTO Employe(id_cnss, nom, prenom, adresse, tel,email,mt_heur_travail, titre) VALUES('"+textBox1.Text.ToString().Trim()+"','"+textBox2.Text.ToString().Trim()+"','"+textBox3.Text.ToString().Trim()+"','"+richTextBox1.Text.ToString().Trim()+"','"+textBox4.Text.ToString().Trim()+"','"+textBox5.Text.ToString().Trim()+"',"+nv+",'"+textBox6.Text.Trim()+"')"; // sql = "UPDATE Employe SET id_cnss ='" + + "' , nom ='" + + "', prenom ='" + + "', adresse ='" + + "', tel ='" + + "', email ='" + + "', mt_heur_travail =" + + ", titre ='" + + "' where id_cnss=" + index; c = new SqlCommand(sql, connection); c.CommandText = sql; // IAsyncResult res; int ex = c.ExecuteNonQuery(); if (ex != null) { MessageBox.Show("employé ajouté"); //dataGridView1.Rows.Clear(); //DataTable table = (DataTable)dataGridView1.DataMember; adapter = new SqlDataAdapter("select * from employe where id_emp=IDENT_CURRENT('EMPLOYE')", connection); adapter.Fill(dTable); //adapter.Update(dTable); dataGridView1.Refresh(); } connection.Close(); } </code></pre> <p>this code add all the rows of the table to the datagridview but i need only to add the latest row added to the database brievely, when the user click under add, </p> <p>i would like that the new row will be added to the datagridview And thank you in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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