主详细数据集-插入后获取主键值 [英] Master Detail Datasets - Getting Primary Key value after insert

查看:53
本文介绍了主详细数据集-插入后获取主键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Windows窗体中有一个Header&Detail强类型数据集.该表格用于处理和记录库存物料的接收,例如键入供应商项目的发票.

Header数据集绑定到Windows控件(例如文本框,日期时间选择器等),而Detail数据集已数据绑定到DATAGRIDVIEW.

标头主键绑定到文本框,每当我添加新行时,该值始终为-1.保存新添加的行后,我想从后端数据库中获取实际值.即使我已选择数据集高级选项以生成用于检索标识列值的select语句,但似乎无法正常工作,或者我可能需要执行另一个sql语句才能刷新Windows控件上的值.如果是这样,我该怎么办?

当前,我有一个绑定导航器,该导航器用于在Header Dataset中添加新行.而且我必须先保存它,然后才能将记录添加到详细数据集中.

这是我当前在窗体上的设置,但实际上我希望它只需单击一下命令按钮就可以发布我的所有Header和Detail记录.然后根据我的标题数据集标识列值的值更新明细记录外键.

我在VB.NET中是相当新的(刷新),因为我一直在使用delphi,如果我使用delphi来开发应用程序,但我想使用Visual Studio切换回去,这对我来说并不难.
我可以访问的任何教程或可以下载的示例代码吗?

谢谢.

Hi,

I have a Header & Detail strongly typed datasets in a windows form. The form is use to process and records inventory item receives, e.g. key-in an invoice from suppliers item.

The Header Dataset is bound to windows controls like text boxes, datetime picker and others while the Detail dataset was databound to a DATAGRIDVIEW.

The header primary key was bound to a textbox and whenever I add a new row, the value is always -1. I want to get the actual value from the backend database after saving the newly added row. Eventhough I have the datasets advanced options selected to generate a select statements to retrieve identity column values but it seems not working or I might need to execute another sql statement just to refresh the values on my windows controls. If thats the case, how would i do that?

Currently I have a Binding Navigator which I used to add new row at my Header Dataset. And I have to save this before i can add records to my detail datasets.

This is my current setup on my form but i actually want it to post all my Header and Detail records in just one click of a command button. then update the Detail records foreign key base on the value of my Header Datasets Identity Column value.

Im quite new (resfresher) with VB.NET, because i''ve been using delp this will not be hard for me if im using delphi to develop the application but I want to switch back using Visual Studio.

Any tutorials i can visit or sample codes that i can download?

Thanks.

推荐答案

如果您查看 [^ ] MSDN杂志文章,可能会有帮助.

它演示了如何使用Web应用程序,但是Windows窗体应用程序的保存过程和步骤应该相同.

希望能帮助到你. :)
If you take a look at this[^] MSDN Magazine Article, it may help.

It demonstrates using a Web App but the Saving process and steps should be the same for a Windows Forms App.

Hope it helps. :)


这篇关于主详细数据集-插入后获取主键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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