Results 1 to 21 of 21

Thread: [RESOLVED] Problem adding multiple records

Threaded View

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Resolved [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
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width