如何GridView控件保存到数据库中的WPF? [英] How to save GridView to DataBase in WPF?
问题描述
在C#中,我经常做这种方式:
in C# I often do it this way:
加载表从数据库中的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);
}
在做相同的(多)上的GridView细胞的变化,我将它保存到数据库是这样的:
After do same(much) changes on GridView Cell, I save it to Database this way:
dataAdapter.Update((DataTable)bindingSource1.DataSource);
假设我加载表GridView控件在WPF中相同的方式。如何保存所有GridView控件的值的数据库? (在WPF的方式:P)
Assume I load the table to GridView the same way in WPF. How to save all GridView value to database? (in WPF way :P)
注:我使用的SQL Server CE数据库。
NB: I'm using SQL Server CE for database.
推荐答案
日期表是在WPF有效的数据源,你可以用它做的结合(与ItemsSource属性),和保存过程是不是真的有关数据网格。
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.
这篇关于如何GridView控件保存到数据库中的WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!