Results 1 to 2 of 2

Thread: problem writing listview data to mysql db

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    problem writing listview data to mysql db

    Hi all i have difficulty writing each row of listview to mysql db. I be happy if some one help me fix it.Thanks



    VB Code:
    1. Private Sub Command11_Click()
    2.  Dim CNN As ADODB.Connection
    3. Set CNN = New ADODB.Connection
    4. CNN.Open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=visualbasic6;USER=root;PASSWORD=;OPTION=3;"
    5.  
    6.  
    7.  Dim sSQL As String
    8. Dim i As Long
    9. For i = 1 To ListView1.ListItems.Count
    10.     sSQL = "INSERT INTO musictest (url,songname,artist,album) "
    11.     sSQL = sSQL & " VALUES('" & ListView1.ListItems.Item(i).Text & "', '"
    12.     sSQL = sSQL & " " & ListView1.Subitems(1) &  ', '"
    13.     sSQL = sSQL & " & ListView1.Subitems(2) &  ', '"
    14.     sSQL = sSQL & " & ListView1.Subitems(3) &  ', '"
    15.    
    16.     MsgBox sSQL
    17.     'etc
    18.     CNN.Execute sSQL
    19. Next
    20.      
    21. MsgBox " The songs are inserted to database successfully"
    22. End Sub


    and points to :CNN.Execute sSQL

    i printed out the sql and the url field was used corectly but not the rest:




    I even tried this and got error:


    VB Code:
    1. sSQL = sSQL & " VALUES('" & ListView1.ListItems.Item(i).Text & "','" & ListView1.SubItems(1) & "','" & ListView1.SubItems(2) & "', '" & ListView1.SubItems(3) & "')"

    VB Code:
    1. Compile error:
    2.  
    3. Method or data member not found

    pointing at :.SubItems

    could u help me fix this.thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: problem writing listview data to mysql db

    Your last version is the way it should be - the only problem is that you are refering to items that don't exist.

    I don't use the Listview much, but would this be more like it?
    VB Code:
    1. With ListView1.ListItems.Item(i)
    2.   sSQL = sSQL & " VALUES('" & .Text & "','" & .SubItems(1) & "','" & .SubItems(2) & "', '" & .SubItems(3) & "')"
    3. End With

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