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?
Nurqalbi
0 Points
3 Posts
Insert data to 2 table in same time
Dec 13, 2012 10:52 AM|LINK
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 :-
but it does'nt work.. it say they have an error.. what problem with my code? can you guys, help me?
raghavendra ...
Participant
1890 Points
435 Posts
Re: Insert data to 2 table in same time
Dec 13, 2012 11:09 AM|LINK
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');Nurqalbi
0 Points
3 Posts
Re: Insert data to 2 table in same time
Dec 13, 2012 12:08 PM|LINK
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Insert data to 2 table in same time
Dec 14, 2012 01:21 AM|LINK
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!
Nurqalbi
0 Points
3 Posts
Re: Insert data to 2 table in same time
Dec 14, 2012 02:18 AM|LINK
Ok thank you for you help and explanation.. i will try to do what you say.. i will give feedback to you..