Results 1 to 8 of 8

Thread: VB Contradicts itself! :)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    VB Contradicts itself! :)

    Well actually it is an SQL statement, but it does contradict itself. It work perfectly while looping through certain folders of files, but gives "Error in INSERT INTO STATEMENT" error. on another folder. All folders contain MP3 files. So why in hell does it create the correct table for one folder and won't work for the other folder? I've posted my code below.
    This is the code that calls a sub to build a table and then adds the info on the files to the table.
    VB Code:
    1. Private Sub Command2_Click()
    2. 'Dim stuff here
    3. Dim Tag As String * 3
    4. Dim Songname As String * 30
    5. Dim Artist As String * 30
    6. Dim Album As String * 30
    7. Dim Year As String * 4
    8. Dim Comment As String * 30
    9. Dim Genre As String * 1
    10. Dim x As Integer
    11. Dim table As String
    12. Dim fname As String
    13. Dim strFilepath As String, strFileName As String, _
    14. strFileSize As String, strArtist As String, _
    15. strTitle As String, strAlbum As String, strTrack As String, _
    16. strFrequency As String, strBitrate As String, _
    17. strLength As String
    18.  
    19.  
    20. 'add the new category to the listbox
    21. lstCategories.AddItem txtcategory.Text
    22.  
    23. 'Create a new table in the Database for the category
    24. Call ADOCreateTable
    25.  
    26. 'connect to the database
    27. Dim Cnn As ADODB.Connection
    28. Dim SQL As String
    29. Set Cnn = New ADODB.Connection
    30. Cnn.Open ConnectionString:="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    31.       "Data Source= c:\windows\system\kamo.mdb;"
    32.  
    33. 'set table = to the category added
    34. table = txtcategory.Text
    35.  
    36. 'Loop through the filelistbox getting info on the files
    37. MusicMaster.File1.Path = txtpath.Text
    38.  
    39. For x = 0 To MusicMaster.File1.ListCount - 1
    40.     fname = MusicMaster.File1.Path & "\" & MusicMaster.File1.List(x)
    41.     Filename = fname
    42. 'Read ID3v1 Tags
    43. Open Filename For Binary As #1
    44.     Get #1, FileLen(Filename) - 127, Tag
    45.     If Not Tag = "TAG" Then
    46.     Close #1
    47.     HasTag = False
    48.        
    49.         End If
    50.         HasTag = True
    51.     Filename = Filename
    52.     Get #1, , Songname
    53.     Get #1, , Artist
    54.     Get #1, , Album
    55.     Get #1, , Year
    56.     Get #1, , Comment
    57.     Get #1, , Genre
    58.     Close #1
    59. '''''''''end of reading file''''''''''''''''''
    60.    
    61. 'Store the info as strings
    62.     strFilepath = fname
    63.     strFileName = MusicMaster.File1.List(x)
    64.     strFileSize = FileLen(fname)
    65.     strTitle = RTrim(Songname)
    66.     strArtist = RTrim(Artist)
    67.    
    68.    
    69.    
    70. 'Use SQL to insert the information in the strings into the table
    71. SQL = "INSERT into " & table &_
    72.  "(FilePath, Filename, Filesize, Artist, Title) VALUES ('" & Replace(strFilepath, "'", "''") _& "','" _
    73. & Replace(strFileName, "'", "''") & "','" _
    74. & Replace(strFileSize, "'", "''") & "','" _
    75. & Replace(strArtist, "'", "''") & "','" _
    76. & Replace(strTitle, "'", "''") & "')"
    77.  
    78.  
    79. Cnn.Execute (SQL)  'ERROR OCCURS HERE
    80.  
    81. Next
    This is the code that in the sub that builds the table:
    VB Code:
    1. Sub ADOCreateTable()
    2.  
    3.    Dim cat As New ADOX.Catalog
    4.    Dim tbl As New ADOX.table
    5.  
    6.    ' Open the catalog
    7.    cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    8.       "Data Source= c:\windows\system\kamo.mdb;"
    9.  
    10.    ' Create a new Table object.
    11.    With tbl
    12.       .Name = categories.txtcategory.Text
    13.       ' Create fields and append them to the new Table
    14.       ' object. This must be done before appending the
    15.       ' Table object to the Tables collection of the
    16.       ' Catalog.
    17.       .Columns.Append "FilePath", adVarWChar
    18.       .Columns.Append "FileName", adVarWChar
    19.       .Columns.Append "Filesize", adVarWChar
    20.       .Columns.Append "Artist", adVarWChar
    21.       .Columns.Append "Title", adVarWChar
    22.    End With
    23.  
    24.    ' Add the new table to the database.
    25.    cat.Tables.Append tbl
    26.  
    27.    Set cat = Nothing
    28.    
    29.    
    30.  
    31. End Sub
    Any help is extremely appreciated. This doesn't make any sense to me.

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Check to see that the folder name or filename doesn't conflict with any of the SQL Keywords or Reserved Words...
    It would be fine if you tell which folders are successfully added and which are not..

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2001
    Location
    Maumelle, AR
    Posts
    624

    ok...

    It adds all the info in the folders: Reggae, Blues, Country, metal, pop. It won't add files in folders named Modern Rock, Hip Hop, Classic Rock. Could it have something to do with that space in the folder name?

  4. #4
    PowerPoster cafeenman's Avatar
    Join Date
    Mar 2002
    Location
    Florida
    Posts
    2,819
    anything that has a space or special character needs to be surrounded with square brackets. In fact, you can surround just about everything with square brackets.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    [yeah,] [it's] [so] [much] [fun]

  6. #6
    Dreamlax
    Guest
    [do] [you] [have] [to] [put] [square] [brackets] [around] [punctuation] [?]

    [what] [happens] [if] [you] [want] [to] [say] [?]

  7. #7
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    [maybe][ ][you][ ][should][ ][test][ ][it][ ][[]][[][[][[][][][][out][]][[][][[[][]]][][]]]
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  8. #8
    PowerPoster rjlohan's Avatar
    Join Date
    Sep 2001
    Location
    Sydney, Australia
    Posts
    3,205
    Different databases accept different punctuation as special characters in different ways. Access, will take single quotes if you submit them like: /'

    Something like that anyway...
    -----------------------------------------
    -RJ
    [email protected]
    -----------------------------------------

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