求C#主从表结构模块详细解决方案

caonimadigepi 2011-12-22 04:51:46
主表以文本框的形式显示,明细表以表格形式显示。请问这样的结构新增、删除、修改、查询各应怎样写?谢谢!
...全文
188 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
slovewithf 2012-07-26
  • 打赏
  • 举报
回复
this.Validate();
this.ordersBindingSource.EndEdit();
this.customersBindingSource.EndEdit();

NorthwindDataSet.OrdersDataTable deletedOrders = (NorthwindDataSet.OrdersDataTable)
northwindDataSet.Orders.GetChanges(DataRowState.Deleted);

NorthwindDataSet.OrdersDataTable newOrders = (NorthwindDataSet.OrdersDataTable)
northwindDataSet.Orders.GetChanges(DataRowState.Added);

NorthwindDataSet.OrdersDataTable modifiedOrders = (NorthwindDataSet.OrdersDataTable)
northwindDataSet.Orders.GetChanges(DataRowState.Modified);

try
{
// Remove all deleted orders from the Orders table.
if (deletedOrders != null)
{
ordersTableAdapter.Update(deletedOrders);
}

// Update the Customers table.
customersTableAdapter.Update(northwindDataSet.Customers);

// Add new orders to the Orders table.
if (newOrders != null)
{
ordersTableAdapter.Update(newOrders);
}

// Update all modified Orders.
if (modifiedOrders != null)
{
ordersTableAdapter.Update(modifiedOrders);
}

northwindDataSet.AcceptChanges();
}

catch (System.Exception ex)
{
MessageBox.Show("Update failed");
}

finally
{
if (deletedOrders != null)
{
deletedOrders.Dispose();
}
if (newOrders != null)
{
newOrders.Dispose();
}
if (modifiedOrders != null)
{
modifiedOrders.Dispose();
}
}
caonimadigepi 2011-12-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wangxinghui8 的回复:]

新增:主表保存文本框的内容,明细表保存表格的内容(主表插入的时候要返回ID,因为明细表有关联)
删除:获取主表ID,去删除主表跟明细表
修改一样
查询根据主表的条件查询
[/Quote]
请问有没有这样的源码给我学习下?
caonimadigepi 2011-12-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wangxinghui8 的回复:]

新增:主表保存文本框的内容,明细表保存表格的内容(主表插入的时候要返回ID,因为明细表有关联)
删除:获取主表ID,去删除主表跟明细表
修改一样
查询根据主表的条件查询
[/Quote]
请问有没有源码发我学习下?
donet菜鸟 2011-12-28
  • 打赏
  • 举报
回复
新增:主表保存文本框的内容,明细表保存表格的内容(主表插入的时候要返回ID,因为明细表有关联)
删除:获取主表ID,去删除主表跟明细表
修改一样
查询根据主表的条件查询
donet菜鸟 2011-12-28
  • 打赏
  • 举报
回复
新增:主表保存文本框的内容,明细表保存表格的内容(主表插入的时候要返回ID,因为子表有关联)
删除:获取主表ID,去删除主表跟明细表
修改一样
查询根据主表的条件查询
caonimadigepi 2011-12-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 seamone 的回复:]

这些微软官方都是有实例的,多去看看。

http://www.cnblogs.com/NETCCB/articles/1335347.html
[/Quote]
请问保存该如何写?最好附上源码。谢谢
caonimadigepi 2011-12-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 seamone 的回复:]

这些微软官方都是有实例的,多去看看。

http://www.cnblogs.com/NETCCB/articles/1335347.html
[/Quote]
请问保存该如何写?最好附上源码。谢谢!
seamone 2011-12-22
  • 打赏
  • 举报
回复
这些微软官方都是有实例的,多去看看。

http://www.cnblogs.com/NETCCB/articles/1335347.html

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧