locked
Insert data to 2 table in same time RRS feed

  • Question

  • User-1119256232 posted

    Hello guys.. i'm using VB 2010. i want to add data into two table in same time..

    fisrt table (Login)

    StaffNo, Password

    Second Table (Profile)

    StaffNo, Password, StaffName, Department, Email, HomeAddress, PhoneNo

    so now, i what i want to do is when i click REGISTER button so the data will be updated in first table and second table.. i'm trying to use this query :-

    insert into newtable
    select Login.value1, Profile.value1
    from Login, Profile
    where table1.StaffNo = table2.StaffNo
    

    but it does'nt work.. it say they have an error.. what problem with my code? can you guys, help me?

    Thursday, December 13, 2012 6:52 AM

Answers

  • User3866881 posted

    so no need to use INNER JOIN right? col1 is refer to what? columm? sorry i'm still learn VB so i dont have more knowledge about that..

    Hi,

    This isn't VB.NET programming language but SQL. So you can use SQL statement to cope with the problem by using SqlCommand as well as SqlConnection.

    Yes, col is your own real columnname, and values are data values to be inserted into the table.

    In fact I suggest you making a Stored Procdure and then throw all of these records into the SP, and then call it directly with the help of SqlCommand.

    Reguards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 13, 2012 9:21 PM

All replies

  • User1534498098 posted

    No, you can not insert data into two tables using one insert statement. instead you can use two insert statement like

     INSERT INTO table1 (col1_1,col1_2)VALUES('data1_1','data1_2')                 
     INSERT INTO table2 (col2_1,col2_2)VALUES ('data2_1','data2_2'); 

     

    Thursday, December 13, 2012 7:09 AM
  • User-1119256232 posted

    No, you can not insert data into two tables using one insert statement. instead you can use two insert statement like

     INSERT INTO table1 (col1_1,col1_2)VALUES('data1_1','data1_2')
     INSERT INTO table2 (col2_1,col2_2)VALUES ('data2_1','data2_2');

    so no need to use INNER JOIN right? col1 is refer to what? columm? sorry i'm still learn VB so i dont have more knowledge about that..

     

    Thursday, December 13, 2012 8:08 AM
  • User3866881 posted

    so no need to use INNER JOIN right? col1 is refer to what? columm? sorry i'm still learn VB so i dont have more knowledge about that..

    Hi,

    This isn't VB.NET programming language but SQL. So you can use SQL statement to cope with the problem by using SqlCommand as well as SqlConnection.

    Yes, col is your own real columnname, and values are data values to be inserted into the table.

    In fact I suggest you making a Stored Procdure and then throw all of these records into the SP, and then call it directly with the help of SqlCommand.

    Reguards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 13, 2012 9:21 PM
  • User-1119256232 posted

    Nurqalbi

    so no need to use INNER JOIN right? col1 is refer to what? columm? sorry i'm still learn VB so i dont have more knowledge about that..

    Hi,

    This isn't VB.NET programming language but SQL. So you can use SQL statement to cope with the problem by using SqlCommand as well as SqlConnection.

    Yes, col is your own real columnname, and values are data values to be inserted into the table.

    In fact I suggest you making a Stored Procdure and then throw all of these records into the SP, and then call it directly with the help of SqlCommand.

    Reguards!

    Ok thank you for you help and explanation.. i will try to do what you say.. i will give feedback to you..

    Thursday, December 13, 2012 10:18 PM