|
-
Jul 19th, 2007, 10:47 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Problem adding multiple records
EDIT: Should have posted in Database forum, so if admin can change please
VB6 and Access 2002
Can anybody see why the following code only adds the first entry.
Say, for example I add 4 records to the DB, all four records are added, but all with the same values as the first record.
I haven't used this method of adding data before, so am I missing something obvious?
Code:
Set cn = New ADODB.Connection
cn.ConnectionString = strConnection & App.Path & "\Membership.mdb"
cn.Open
Dim adoCommand As ADODB.Command
Set adoCommand = New ADODB.Command
For i = 0 To ctr - 1
iMonth = CInt(cmbMM(i).Text)
dtDate = CDate(cmbDD(i).Text & "/" & cmbMM(i).Text & "/" & cmbYY(i).Text)
strDay = cmbDay(i).Text
strType = cmbType(i).Text
strVenue = cmbVenue(i).Text
strTimes = cmbTime1(i).Text & " to " & cmbTime2(i).Text & " - " & cmbTime3(i).Text & " to " & cmbTime4(i).Text
strYear = cmbYY(i).Text
strSQL = "INSERT INTO tbl_CourseList (Course_Month, Course_Date, " & _
"Course_Day, Course_Type, " & _
"Course_Venue, Course_Times, Course_Year)" & _
" Values (iMonth, dtDate, strDay, strType, strVenue, strtimes, strYear)"
With adoCommand
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = strSQL
.Prepared = True
.Parameters.Append .CreateParameter(, adInteger, adParamInput, 50, iMonth)
.Parameters.Append .CreateParameter(, adDate, adParamInput, 50, dtDate)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, strDay)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, strType)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, strVenue)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, strTimes)
.Parameters.Append .CreateParameter(, adVarChar, adParamInput, 50, strYear)
.Execute , , adCmdText + adExecuteNoRecords
'note: the last two arguments used for Execute here makes the execution of the command faster
End With
Next
cn.Close
Set cn = Nothing
Also, what do I set the adoCommand to at the end to tidy it up?
Last edited by aikidokid; Jul 19th, 2007 at 10:48 AM.
Reason: Posted in wrong forum
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
|