简体   繁体   English

如何使用VB.NET将数据插入两个表?

[英]How to Insert Data into Two Tables Using VB.NET?

I have a problem on how to insert data into two different table. 我有一个关于如何将数据插入两个不同的表的问题。 So my requirements is this. 所以我的要求就是这个。

  • The user will fill out all the needed information under Employee Information then in order to save the data the user will click the SAVE button. 用户将在“员工信息”下填写所有必需的信息,然后为了保存数据,用户将单击“保存”按钮。 Under Group Details, The user need to click all the needed information on the dropdown menu and input on the textbox of the table grid view before clicking the ADD Link, after this the page will load displaying the Added Job Title and business group details. 在“组详细信息”下,用户需要在下拉菜单中单击所有需要的信息,然后在单击“添加链接”之前输入表格网格视图的文本框,此后页面将加载显示“添加的作业标题”和业务组详细信息。 The user is allowed to input as many Job title as the user want. 允许用户输入与用户想要的一样多的作业标题。 Last is the Add New Employee to Headcount list, the user need to click the PROCEED button in order to add the headcount of the added Employee Information. 最后是Add New Employee to Headcount列表,用户需要单击PROCEED按钮以添加添加的Employee Information的人数。 I already finished the table but I have problems in saving the data that I input. 我已经完成了表格,但是我在保存输入的数据时遇到了问题。

So my first table looks like this Before and I edit it and now this is my table Now 所以我的第一个表看起来像这样之前我编辑它现在这是我的表现

So my problem is this, in my database i have two table. 所以我的问题是这个,在我的数据库中我有两个表。

EMP_MASTERTBL has these columns

 SEQID | MASTERID | firstname | lastname | Country | JOBTITLE

and EMPGROUP_TBL has these columns

MASTERID | business_unit | division | Sub_Division

Now everytime I click save the jobtitle will not be able to save in the EMP_MASTERTBL so I create a code in VB.Net that will update the EMP_MASTERTBL table when I click the add button under Group Details. 现在,每次单击保存时,作业标题将无法保存在EMP_MASTERTBL因此我在VB.Net中创建了一个代码,当我单击“组详细信息”下的“添加”按钮时,该代码将更新EMP_MASTERTBL表。

Here's my codes. 这是我的代码。

If UpdateInsDelRecord("INSERT INTO EMPGROUP_TBL (MASTERID, BUSINESS_UNIT, " & _
                  "DIVISION, SUB_DIVISION, CLASSIFICATION, SUB_CLASSIFICATION) VALUES " & _
                  "('" + HandleQuote(Me.lblval_Empid.Text) + "', " & _
                  "'" + Me.ddl_BusinessUnit.SelectedValue.ToString() + "' ," & _
                  "'" + val_division + "' ," & _
                  "'" + val_subdivision + "' ," & _
                  "'" + Me.ddl_Classification.SelectedValue.ToString() + "' ," & _
                  "'" + Me.ddl_SubClassification.SelectedValue.ToString() + "')" & _
                  ";" & _
                   "UPDATE EMP_MASTERTBL SET JOBTITLE = '" + Me.txtJobtitle.Text + "' " & _
                   "WHERE MASTERID = '" + Me.lblval_Empid.Text + "'") = True Then
    Return True
    Response.Redirect("eHR_EmpMaintenance.aspx")
Else
    Return False
End If

But the user must be able to add as many as Jobtitle as the user want. 但是用户必须能够像用户想要的那样添加Jobtitle。 So I'm thinking that I'll just write another query for that? 所以我想我会为此写另一个查询? How can I add the Group Details and be able to add as many as Jobtitle as the user want? 如何添加组详细信息并能够添加与用户想要的Jobtitle一样多的组? Help me with this please. 请帮帮我。

Thanks. 谢谢。

I am not very much sure with your UpdateInsDelRecord method. 我对您的UpdateInsDelRecord方法不太确定。 If it is simply executing the sql query with return type Boolean, you can write another insert/ update query with ; 如果只是执行返回类型为Boolean的sql查询,则可以编写另一个插入/更新查询; separator. 分隔器。 And I belive you want to update the field Jobtitle in EMPMASTER_TBL table. 我相信你想要在EMPMASTER_TBL表中更新字段Jobtitle。

If UpdateInsDelRecord("INSERT INTO EMPGROUP_TBL (MASTERID, BUSINESS_UNIT, " & _
                          "DIVISION, SUB_DIVISION, CLASSIFICATION, SUB_CLASSIFICATION) VALUES " & _
                          "('" + HandleQuote(Me.lblval_Empid.Text) + "', " & _
                          "'" + Me.ddl_BusinessUnit.SelectedValue.ToString() + "' ," & _
                          "'" + val_division + "' ," & _
                          "'" + val_subdivision + "' ," & _
                          "'" + Me.ddl_Classification.SelectedValue.ToString() + "' ," & _
                          "'" + Me.ddl_SubClassification.SelectedValue.ToString() + "')" &_
                          ";" &_ 
                           "UPDATE EMPMASTER_TBL SET JOBTITLE = "Your value" WHERE empno = "YOur emp id"  " ) = True Then
        Return True
        Response.Redirect("eHR_EmpMaintenance.aspx")
    Else
        Return False
    End If

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM