添加新记录时,绑定源与关系不起作用 [英] Bindingsource with relation not working when adding new record

查看:60
本文介绍了添加新记录时,绑定源与关系不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一组文本框和数据网格的表单,我目前设置了2个绑定源和一个包含2个表和关系的数据集,第一个BS是主BS,所有文本框都在表单中绑定到这个BS,第二个BS的数据源绑定到第一个BS,datamember设置为关系,datagrid绑定到这个BS。



选择操作正常,更新操作也正常,问题在于添加新记录时保存,第一个BS根本不保存数据而子节点保存记录但关系字段保存为-1 ,显然那是因为父母在保存时没有设置,所以正确的ID字段没有得到转发。



我尝试过:



我尝试过Addnewrow方法无济于事,我尝试过AcceptChanges,GetChanges等没有结果,tableadapter.update根本就不会保存数据回到db,没有出现错误,我尝试使用Onrowupdating和RowUpdated调试没有结果,连接正常,表适配器具有所有命令(插入,更新,删除,选择)。我已经尝试过使用tableadaptermanager而没有结果。



我刚试过的最后一件事是使用事务,但它仍然没有保存回数据库。



简而言之,问题是设置这种情况的正确方法是什么:IE



2桌子(订单, OrderDetails)

1个数据集,包含2个表和OrderID字段的关系

2个表适配器每个表一个

2个绑定源:1个绑定订单文本框和绑定数据网格订单详细信息。



我知道如何手动执行此操作,我想知道的是如何自动化所有这些使用绑定源,因为这是整点,手动操作会打败我正在寻找的目的。

I have a form that has a set of textboxes and a datagrid, i've currently setup 2 binding sources and one dataset containing the 2 tables and the relation, the first BS is the master BS, all the textboxes in the form are bound to this BS, the second BS has the Datasource bound to the the First BS and the datamember is set to the relation, the datagrid is bound to this BS.

The select operation works fine, the Update operations work fine as well, the problem comes with saving when adding a new record, the first BS does not save data at all and the child saves the record but the relation field gets saved with -1, obviously that's because the parent is not set at the time of saving so the proper ID field does not get relayed.

What I have tried:

I've tried the Addnewrow method to no avail, i've tried the AcceptChanges, GetChanges etc with no result, the tableadapter.update simply will not save data back to db, no error is presented , i've tried to debug using Onrowupdating and RowUpdated with no result, connection is ok, the table adapter has all the commands ( Insert, update, Delete, Select). i've tried using a tableadaptermanager with no result.

the last thing i just tried was using transactions and still it does not save back to the db.

In short the question would be what's the proper way to setup such scenario: I.E

2 Tables (Orders, OrderDetails)
1 dataset with this 2 tables and a relation on the OrderID field
2 tables adapters one for each table
2 bindingsources : one binding the Orders textboxes and one binding the datagrid for Orders Details.

I know how to do this manually, what i would like to know is how to automate all of this using the bindingsources since that's the whole point and doing it manually would defeat the purpose i'm looking for here.

推荐答案

如果你不能更新全部3 ,然后单独尝试订单。如果有效,等等。



你没有显示代码。人们只能猜出你的问题是什么。



细节显然取决于订单。订单没有添加。以下内容无关紧要。
If you can't update "all 3", then just try "Orders" by itself. If that works, etc.

You show no code. One can only guess at what your problem is.

Details obviously depends on Orders. Orders are not being added. What follows is irrelevant.


这篇关于添加新记录时,绑定源与关系不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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