-
Aug 28th, 2015, 11:13 PM
#1
Thread Starter
Hyperactive Member
Help: joining 2 statement (Insert and Update)
Is it possible to join 2 different statement in one query?
Code:
I use this to insert record
Dim strQry As String
strQry = "INSERT INTO tab2 " & _
"(LinkID, Addr, Remarks) " & _
"VALUES (" & _
"'" & txtLink.Text & "', " & _
"'" & txtAddr.Text & "', " & _
"'" & txtRemarks.Text & "'" & _
")"
conn.Execute strQry
I use this to update
Dim strQry As String
strQry = "UPDATE tab1 SET " & _
"Addr='" & txtAddr.Text & "', Remarks='" & txtRemarks.Text & "' " & _
"WHERE LinkID='" & txtLink.Text & "'"
conn.Execute strQry
How can I combine both of these?
any help?
-
Aug 29th, 2015, 01:10 AM
#2
Thread Starter
Hyperactive Member
Re: Help: joining 2 statement (Insert and Update)
Additional information:
For example:
I insert record on table2 named 'tab2'
LinkID = 'E-001'
Address = txtaddr.Text
Remarks = txtRemarks.Text
At the same time it must update table1 name 'tab1'
based on new inserted record using (LinkID field).
-
Aug 29th, 2015, 01:33 AM
#3
Thread Starter
Hyperactive Member
Re: Help: joining 2 statement (Insert and Update)
In mysql, query worked well.
Code:
UPDATE `tab1` SET `Addr`='SPL',`Remarks`='NEW HOME' WHERE `LinkID`='E-001';INSERT INTO `tab2` (`LinkID`,`Addr`,`Remarks`) VALUES ('E-001','SPL', 'NEW HOME');
But when I tried to run it in vb6, error occurs.
-
Aug 29th, 2015, 01:39 AM
#4
Thread Starter
Hyperactive Member
Re: Help: joining 2 statement (Insert and Update)
-
Aug 29th, 2015, 11:45 AM
#5
Re: Help: joining 2 statement (Insert and Update)
meaning is that if you insert some value in some table ( say in this case tab1)
basing on the the inserted values another table ( say tab2) will get updated / inserted etc..
so that tab2 is a watch dog or what ever
by the error details it appears that you are using MySQL
use the TRIGGERS of MySQL it does lot work for you , just google it.
next important is you are using ODBC 3.51 driver , nope don't use it mysql is providing dot net connector just download and use it
and as for as the error is concern it points to the error in the SQL syntax
i would like to draw your attention to this link , which is similar to your issue
-
Aug 29th, 2015, 11:47 AM
#6
Re: Help: joining 2 statement (Insert and Update)
One more important thing is
it is possible to execute INSERT and UPDATE statements with single command object
for safe side use MySql TRANSACTION
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|