如何在WPF中更改数据库?

发布于 2024-09-05 21:29:35 字数 1010 浏览 1 评论 0原文

将access数据库拖入designer xsd中,工具包:datagrid从资源中获取datacontext 通过此绑定正确显示表格内容。按下按钮栏中的按钮,即可正确显示每一行。删除行和添加行也在数据网格中工作

,但是,当我按下按钮列添加新行或删除行时,底层数据库没有更改,如果不使用 ADO,如何将更改从数据网格提交到 WPF 中的数据库。网 ?

以下代码是我尝试的不起作用

private void datagrid2_delete(object sender, RoutedEventArgs e)
        {

            Button showButton = (Button)sender;

            //person p = (person)showButton.DataContext;

            DataRowView ds = (DataRowView)showButton.DataContext;

            //DataSet1.customertableRow p = (DataSet1.customertableRow)ds;
            //ds.BeginEdit();
            //ds.Delete();
            //ds.EndEdit();

            /*
            DataSourceProvider provider = (DataSourceProvider)this.FindResource("Family");
            WpfApplication1.DataSet1.customertableDataTable table =
            (WpfApplication1.DataSet1.customertableDataTable)provider.Data;
            table.AddcustomertableRow("hello3", 5, System.DateTime.Today);
            table.AcceptChanges();
}

Drag access database into designer xsd, toolkit:datagrid get datacontext from resources
correctly show the table content through this binding. Press button in the button column, can show each row correctly. delete row and add row also work in datagrid

however, when i press button column to add a new row or delete a row, there is no change in the underlying database, how to commit the changes from datagrid to database in WPF if not using ADO.net ?

The following code is what i try do not work

private void datagrid2_delete(object sender, RoutedEventArgs e)
        {

            Button showButton = (Button)sender;

            //person p = (person)showButton.DataContext;

            DataRowView ds = (DataRowView)showButton.DataContext;

            //DataSet1.customertableRow p = (DataSet1.customertableRow)ds;
            //ds.BeginEdit();
            //ds.Delete();
            //ds.EndEdit();

            /*
            DataSourceProvider provider = (DataSourceProvider)this.FindResource("Family");
            WpfApplication1.DataSet1.customertableDataTable table =
            (WpfApplication1.DataSet1.customertableDataTable)provider.Data;
            table.AddcustomertableRow("hello3", 5, System.DateTime.Today);
            table.AcceptChanges();
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒解孤独 2024-09-12 21:29:35

谢谢。

Datacontext 没有 savechanges 选项可供选择
我google了一下Linq dbml不支持Access,只支持MS SQL服务器,这意味着datacontext.XXXXX不能与Access数据库一起使用

最后,我使用ADO .Net,OleCommand。这是唯一的选择

Thanks.

Datacontext do not have savechanges options to choose
i google that Linq dbml do not support Access and only support MS SQL server that means datacontext.XXXXX can not be used with Access database

At last, i use ADO .Net , OleCommand. It 's the only choice

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文