在3层应用程序设计中保存DataGridView更改 [英] Save DataGridView changes in 3 layer application design

查看:92
本文介绍了在3层应用程序设计中保存DataGridView更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



起初让我原谅我的英语不好。



i试试清楚地传达我的问题。



我的应用程序假设连接到MS Access数据库。



第一层:包含与我的表字段相关的属性



第二层:一个函数返回请求的行作为同一个表的DataTable



第三层:从第二层获取DataTable后,将其作为同一个表的DataTable返回。



最后在Presentation层中我将DataTable放入BindingSource并分配它到DataGridView.DataSource。



好​​的,到目前为止我可以正确看到请求的行但是,如何保存用户在DataGridView中所做的所有更改? br $> b $ b

***************************



1:创建一个循环来更新每一行是否正确?



2:或者我必须将所有更改发送为Da taTable to database?



主要问题:



第一个解决方案我知道我该怎么做它但是第二次我找不到任何办法,因为我不知道如何通过3层将DataTable发送到数据库。



如果我的问题是模糊的,请告诉我

hello everybody

at first let me to excuse for my bad english.

i try to convey my problem clearly.

my application suppose to connect to a MS Access database.

First layer: consist of property related to my table fields

Second layer: a function return requested rows as DataTable of same table

Third layer: after getting DataTable from second layer, return that as DataTable of same table.

Finally in Presentation layer I put DataTable in a BindingSource and assign it to DataGridView.DataSource.

Ok, I can see the requested rows correctly so far but, how can I save all changes which has made by user in DataGridView?

***************************

1: Is it correct to create a loop to Update each row separetly?

2: Or I must send all changes as DataTable to database?

Main problem:

for the first solution I know that how should I do it but for second I can't find any way to do it because I don't know how I can send DataTable to database through 3 layer.

if my question is vague, please tell me

推荐答案

选择方法取决于您的要求。



更新多个您可以立即使用 SqlBulkCopy [ ^ ]。用演示源代码查看这篇详细的文章。

SqlBulkCopy-批量插入记录并在使用C#和VB.Net存在记录时更新现有行 [ ^ ]



如果你已经实现了这个或者你的要求不是这个,请告诉我。



希望,它有帮助:)
Selecting a approach depends on your requirement.

To update multiple rows at once you may use SqlBulkCopy[^]. check this detailed article with demo source code.
SqlBulkCopy- Bulk Insert records and Update existing rows if record exists using C# and VB.Net[^]

In case you have implementing this or if your requirement is other than this, please let me know.

Hope, it helps :)


这篇关于在3层应用程序设计中保存DataGridView更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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