N/APosted on - 01/10/2015
Hello! I installed DataGridView1 on the form and then through its property DataSource connect to database. When program starts it shows me records of my database, but then when I add new records they do not appear in program, even after restarting computer. I use DataGridView1.Update() . Please advise what am I doing wrong?
Updating data in DataGridView while adding records in database
You can use the SqlAdapter for auto update of your DataGrid. See command examples below that you can use appropriately in your program.
SqlConnection sql1 = new SqlConnection("Data Source=localhost;Initial Catalog=………. ;Integrated Security=True");
SqlDataAdapter sqlda1 = new SqlDataAdapter();
DataTable dtab1 = new DataTable();
SqlCommand sel1 = new SqlCommand("select ……………….", sql1);
sqlda1.SelectCommand = sel1;
SqlCommandBuilder cmbuilder = new SqlCommandBuilder(sqlda1);
this.dataGridView1.DataSource = dtab1;
In the button Save put the following:
The above commands if used correctly, should update the grid as and when database is updated by program