VB.NET中的主要和详细问题 [英] Master and Detail Problem in VB.NET

查看:62
本文介绍了VB.NET中的主要和详细问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好所有访客
我有2张桌子.表SaleHeader是主表,表SaleDetail是明细表.在主表中,有一个主键(SaleCode),它是明细表中的外键.在明细表中,有一个主键(SaleDetailCode).因此,在明细表中,有一个外键(SaleCode)和主键(SaleDetailCode).
保存时,我想将主表中的所有数据保存到Table(SaleHeader)中并将所有明细数据(使用DataGridView显示所有数据)保存到SaleDetail表中.
在我的源代码中是:

Hi all visitors
i have 2 tables. Table SaleHeader is a master table and Table SaleDetail is a detail table.In master table, there is a primary key(SaleCode) and it is a foreign key in detail table.In detail table, there is a primary key(SaleDetailCode). So in detail table, there are one foreign key(SaleCode) and primary key(SaleDetailCode).
when i save, i want to save all data in master table to Table(SaleHeader) and all detail data(use DataGridView to show all data) to SaleDetail table.
in my source code is:

Me.SaleHeaderBS.EndEdit()
Me.SaleHeaderTA.Update(Me.VinaSaleDS.SalesHeader)
Me.SaleDetailBS.Current("Salecode") = Me.txtDocnum.Text.Trim
Me.SaleDetailBS.EndEdit()
Me.SaleDetailTA.Update(Me.VinaSaleDS.SalesDetail)



但它出错并显示"SaleDetailCode不能为空"的消息.
注意:
对于主表中的SaleCode,我使用文本框输入销售代码.
for SaleDetailCode我隐藏在DataGrid中,但我希望它自动增加表中的coz SaleDetailCode自动编号.

请帮助我有关如何将数据从主数据和明细数据保存到表的信息.

最好的问候,
我在DataGrid中隐藏了SaleDetailCode的TONY



but it error and show me the message that "SaleDetailCode couldn''t null".
Note:
for SaleCode in Master Table, i use text box to input Sale Code.
for SaleDetailCode i hide in DataGrid, but i want it automatically increase coz SaleDetailCode autonumber in table.

Please help me about how i can save data from master and detail to tables.

Best Regards,
TONY

推荐答案

,但我希望它自动增加表中的coz SaleDetailCode自动编号.
这与表设计有关,而不是通过代码.

将其设置为身份"列 [ 2.选择"SaleDetailCode"列
3.请参阅下面的列的属性.
4.如果在身份"列中有一个选项,请选择-标记为是
5.您也可以将增量定义为任何数字.默认情况下为1.
for SaleDetailCode i hide in DataGrid, but i want it automatically increase coz SaleDetailCode autonumber in table.
This has to do with table design and not via code.

Make it an Identity column[^] with a defined increment step.

It would be something like:
1. Go to ''Design Table''
2. Select the column of ''SaleDetailCode''
3. See at the properties of the column below.
4. There is an option of making it if ''Identity'' column - mark it yes
5. You can also define the increment to any number. By default it is 1.


除了
S Mewara告诉我们的过程
这意味着
将SaleDetailCode标记为一个身份隐含的信息后
您可以使用max Function
如下增加SaleDetailCode
并在单击保存"按钮后调用此功能
或每当您加载表单时..
With Addition To
the process what is Told by S Mewara
that means
after marking the SaleDetailCode as An Identity Increament To One
You can use The max Function
to Increase the SaleDetailCode as Follows
and Call this function after you Click Your Save button
or Whenever you load the Form..
Public Sub Max_Id()
        Dim sd As New SqlDataAdapter("Select max(SaleDetailCode) from SaleDetail", myCon.con())
        Dim dt As New DataTable
        sd.Fill(dt)
        If (dt.Rows(0)(0).ToString() <> Nothing) Then
            txtEid.Text = Convert.ToInt32(dt.Rows(0)(0).ToString()) + 1
        Else
            txtEid.Text = "1"

        End If
    End Sub



我也建议您在
中使用文本框 数据网格的位置以输入SaleDetailCode
然后隐藏文本框
在这里,我提供了与我正在使用的连接类相同的名称为 txtEid myCon 的文本框.
使用连接所获取的内容



Also I will Suggest You to use a Textbox in
Place Of datagrid to Input the SaleDetailCode
and then hide The Textbox
here I have Provided the same Taking a TextBox named txtEid and myCon is the connection Class What i am using.
use the Connection what you have Taken


这篇关于VB.NET中的主要和详细问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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