arkeysi arkeysi - 17 days ago 5
SQL Question

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.
    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.

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. 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? Help me with this please.

Thanks.

Answer

I am not very much sure with your UpdateInsDelRecord method. If it is simply executing the sql query with return type Boolean, you can write another insert/ update query with ; separator. And I belive you want to update the field Jobtitle in EMPMASTER_TBL table.

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
Comments