将内容行与datagrid上的现有表与数据库值进行比较 [英] comparing contents rows with existing table on datagrid with database values

查看:86
本文介绍了将内容行与datagrid上的现有表与数据库值进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请点击我们正在使用的解决方案,其中有数据表通过网页上的数据集显示..当页面加载时,该表默认位于该页面...并且有一个按钮称为保存按钮。此数据表用户可以编辑...当用户按下保存按钮而不对数据表进行任何更改时,它将运行存储过程并将结果更新到数据库表仍然如果用户没有做任何变化...



现在这里是问题部分:::

现在用户要求是这样他们想要更新的数据库只有那些行,其内容已被更改..每个行和每行...不含


如果我比较数据表的内容带有sql servers数据库表的网页..如果内容不同,那么我就可以运行存储过程,而后者又会更新数据库......但我怎么能这样做......我非常迫切需要帮助...





谢谢

Hi,
Rightnow the solution we are using in which there is datatable displayed via dataset on webpage..When page loads this table will be by default at that page...and there is one button called as save button..this data table user can edit...and when the user press the save button with out making any changes in datatable it will run a stored procedure and update the result to database table still if users havent made any of changes...

Now here is the problem part :::
now the user requirements is like this they want to update in database only those rows , whose contents has been changed ..NOT OF EACH AND EVERY ROW....

according to me if i compare the content of data table on webpage with sql servers database table..and if contents are different only then i can run stored procedure which in turn update the database...But how can I do this..I need help very urgently...


Thanks

推荐答案

DataTable有一个名为GetChanges的方法,它返回在调用最后一个AcceptChanges后对表进行的所有更改。



请参阅此处 [ ^ ]更多

[代码示例]

DataTable has a method called GetChanges which returns all changes made to the table after the last AcceptChanges is called.

see here[^] for more
[Code sample]
private void UpdateDataTable(DataTable table, 
    OleDbDataAdapter myDataAdapter)
{
    DataTable xDataTable = table.GetChanges();

    // Check the DataTable for errors. 
    if (xDataTable.HasErrors)
    {
        // Insert code to resolve errors.
    }

    // After fixing errors, update the database with the DataAdapter 
    myDataAdapter.Update(xDataTable);
}


这篇关于将内容行与datagrid上的现有表与数据库值进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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