Results 1 to 3 of 3

Thread: [RESOLVED] Having Problem with the INSERT syntax in VB6...

  1. #1

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    Resolved [RESOLVED] Having Problem with the INSERT syntax in VB6...

    Hi guys!



    I'm having a problem in the INSERT SYNTAX.

    I'm currently using MS ACCESS 2007 temporarily because my installer of SQL Server got broken. In my database, I have an "IDNo" set as auto increment so every time I insert a new record it will automatically have a number.

    But the problem is that normally in SQL Server you won't require to add the indicated field with an auto increment and if you use a MS ACCESS 2007 as a database, there will be an error in the syntax saying that the number of query values and destination fields are not the same.


    Code:
        For x = 1 To lvSubject.ListItems.Count
        
            Set rs = New ADODB.Recordset
            rs.Open "INSERT INTO tblStudinfo VALUES('" & txtStudNo.Text & "', '" & txtFirstName.Text & "', '" & txtMI.Text & "', '" & txtlastName.Text & "', '" & cboGender.Text & "', '" & lvSubject.ListItems.Item(x) & "')", cnx, adOpenKeyset, adLockPessimistic
        
        Next
    ....before the txtStudNo there is a field named "IDNo" with an auto increment.

    Plz help.. ASAP
    tnx!



    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Having Problem with the INSERT syntax in VB6...

    If you explicitely include list of fields your problem will go away regardless of any db:

    insert into (f1, f2, f3) values (v1, v2, v3)

    List of fields can be in any order, however as long as list corresponding values are in the same order it should be alright.

  3. #3

    Thread Starter
    Fanatic Member louvelle's Avatar
    Join Date
    Jun 2008
    Posts
    513

    Re: Having Problem with the INSERT syntax in VB6...

    Ahh... I see..Thank you RhinoBull.




    Manny Pacquiao once posted in his twitter:
    It doesn't matter if the grammar is wrong, what matter is that you get the message

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