[英]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.
所以我的要求就是这个。
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.