in C# I often do it this way:
Load Table from DataBase to GridView
SqlCeDataAdapter dataAdapter;
try
{
String connectionString = connStr;
String selectCommand = "select * from Table_Name";
dataAdapter = new SqlCeDataAdapter(selectCommand, connectionString);
commandBuilder = new SqlCeCommandBuilder(dataAdapter);
DataTable table = new DataTable();
dataAdapter.Fill(table);
bindingSource1.DataSource = table;
DataGridView1.DataSource = bindingSource1;
}
catch (SqlCeException ex)
{
MessageBox.Show(ex.Message);
}
After do same(much) changes on GridView Cell, I save it to Database this way:
dataAdapter.Update((DataTable)bindingSource1.DataSource);
Assume I load the table to GridView the same way in WPF. How to save all GridView value to database? (in WPF way :P)
NB: I’m using SQL Server CE for database.
Date table is a valid data source in wpf, you can do the binding with it(with ItemsSource property), and the saving procedure is not really related to the data grid.
just hold a reference to your table.