Hi. I have followed this tutorial and i am now showing data in my DataGridView:
Code:
void FillData()
{
// 1
// Open connection
using (SqlCeConnection c = new SqlCeConnection(
Properties.Settings.Default.DataConnectionString))
{
c.Open();
// 2
// Create new DataAdapter
using (SqlCeDataAdapter a = new SqlCeDataAdapter(
"SELECT * FROM Animals", c))
{
// 3
// Use DataAdapter to fill DataTable
DataTable t = new DataTable();
a.Fill(t);
// 4
// Render data onto the screen
dataGridView1.DataSource = t;
}
}
}
Now I want to be able to modify the data and write it back to the database. How would i do this ? Create a function called SaveData and:
- create a connection
- create a new adapter ( that writes )
- create the datatable
- write datatable to new adapter using the connection
I was wondering if that thought process is correct. I barely have any C# coding experiences alltho this does not seem so hard. Help is appreicated