WPF:更改数据网格以反映在数据库表中 [英] WPF: Changes in datagrid to reflect in database table

查看:168
本文介绍了WPF:更改数据网格以反映在数据库表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在WPF中使用Datagrid遇到问题.我正在忙着编写WPF浏览器应用程序.我在页面上声明了一个数据网格,如下所示:

Hi people,

I have a problem with the Datagrid in WPF. I''m busy writing a WPF browser application. I have a datagrid declared on my page as follows:

<DataGrid  ItemsSource="{Binding}" AutoGenerateColumns="True" Height="462" Name="dgRepair" VerticalAlignment="Top" Grid.ColumnSpan="3" Margin="0,0,1,0" RowEditEnding="dgRepair_RowEditEnding" />



然后我有代码将表中的数据绑定到此datagrid



Then I have code to bind data from a table to this datagrid

SqlDataAdapter RepairAD;
DataSet repairDS;
        string sqlIns = @"select * from table";
        SqlCommand cmd = new SqlCommand(sqlIns, conn);
        RepairAD = new SqlDataAdapter(cmd);

        repairDS = new DataSet();
        RepairAD.Fill(repairDS, "Repair");
        dgRepair.DataContext = repairDS.Tables["Repair"].DefaultView;
        dgRepair.UpdateLayout();



我需要的代码是根据数据网格中所做的更改来更新SQL数据库中的表.

我尝试了这段代码,但没有执行任何操作



What I need is code to update the table in the SQL database from the changes that are made in the datagrid.

I tried this code but it did nothing

SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(RepairAD);
            RepairAD.Update(repairDS, "Repair");



如果有人可以帮助,那就太好了.

谢谢

ps:即时通讯使用的是datagrid,而不是datagridview



If anyone can help it would be awesome.

Thanks

ps: im using a datagrid and not a datagridview

推荐答案

看看:
WPF DataGrid实用示例 [
Take a look at:
WPF DataGrid Practical Examples[^]

Regards
Espen Harlinn


这篇关于WPF:更改数据网格以反映在数据库表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆