If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > mutiple insert statement problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-26-03, 05:55
sun919 sun919 is offline
Registered User
 
Join Date: May 2003
Posts: 4
Exclamation mutiple insert statement problem

hi there,
I have a question regarding insert multiple data into multiple table
The program work fine when i only insert into 1 table but inserting another set of data into another table the program won't do it
this is what i wrote

Dim rs As New ADODB.Recordset
Dim rs1 As New ADODB.Recordset
Dim path As String

Private Sub Command2_Click()
Dim a As String

path = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\present\vb\maintenance.mdb"

a = "INSERT INTO MachineStatus(machineCode,machineInfo,expiretype," & _
"hourCode,expireCode)VALUES('" & machcode & "','" & machinfo & _
"','" & maintenancetype.Text & "','" & hourcod & " ','" & expirecod & "')"

rs1.Open a, path, adOpenStatic, adLockOptimistic
'rs1.Update

'rs1.Close

a = "INSERT INTO MachineName(machineName,MachineCode)VALUES('" _ & name1.Text & "','" & machcode & "')"
rs2.Open a, path, adOpenStatic, adLockOptimistic
'rs2.Update
'rs2.Close

Note: I've try use update and close adding to it but it still won't work
many thanks
sun
Reply With Quote
  #2 (permalink)  
Old 06-03-03, 17:06
Ad Dieleman Ad Dieleman is offline
Registered User
 
Join Date: Jan 2003
Location: Dordrecht, The Netherlands
Posts: 95
Re: multiple insert statement problem

Using a recordset with an INSERT statement doesn't make much sense because the recordset will not return any data. Instead, do something like this:

Dim con As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim path As String

Private Sub Command2_Click()
Dim a As String, n as Long

path = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\present\vb\maintenance.mdb"

Set con = New ADODB.Connection
con.ConnectionString = path
con.Open

a = "INSERT INTO MachineStatus(machineCode,machineInfo,expiretype," & _
"hourCode,expireCode)VALUES('" & machcode & "','" & machinfo & _
"','" & maintenancetype.Text & "','" & hourcod & " ','" & expirecod & "')"

Set cmd = New ADODB.Command
With cmd
.ActiveConnection = con
'I might be wrong about adCommandText,
'I don't have VB on the machine I'm writing this on
.CommandType = adCommandText
.CommandText = a
'After execution n contains the number of records processed
.Execute n
End With

Etc. for the second INSERT statement

Hope this helps.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On