|
-
May 3rd, 2002, 10:29 PM
#1
Thread Starter
Fanatic Member
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:
Private Sub Command2_Click()
'Dim stuff here
Dim Tag As String * 3
Dim Songname As String * 30
Dim Artist As String * 30
Dim Album As String * 30
Dim Year As String * 4
Dim Comment As String * 30
Dim Genre As String * 1
Dim x As Integer
Dim table As String
Dim fname As String
Dim strFilepath As String, strFileName As String, _
strFileSize As String, strArtist As String, _
strTitle As String, strAlbum As String, strTrack As String, _
strFrequency As String, strBitrate As String, _
strLength As String
'add the new category to the listbox
lstCategories.AddItem txtcategory.Text
'Create a new table in the Database for the category
Call ADOCreateTable
'connect to the database
Dim Cnn As ADODB.Connection
Dim SQL As String
Set Cnn = New ADODB.Connection
Cnn.Open ConnectionString:="Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= c:\windows\system\kamo.mdb;"
'set table = to the category added
table = txtcategory.Text
'Loop through the filelistbox getting info on the files
MusicMaster.File1.Path = txtpath.Text
For x = 0 To MusicMaster.File1.ListCount - 1
fname = MusicMaster.File1.Path & "\" & MusicMaster.File1.List(x)
Filename = fname
'Read ID3v1 Tags
Open Filename For Binary As #1
Get #1, FileLen(Filename) - 127, Tag
If Not Tag = "TAG" Then
Close #1
HasTag = False
End If
HasTag = True
Filename = Filename
Get #1, , Songname
Get #1, , Artist
Get #1, , Album
Get #1, , Year
Get #1, , Comment
Get #1, , Genre
Close #1
'''''''''end of reading file''''''''''''''''''
'Store the info as strings
strFilepath = fname
strFileName = MusicMaster.File1.List(x)
strFileSize = FileLen(fname)
strTitle = RTrim(Songname)
strArtist = RTrim(Artist)
'Use SQL to insert the information in the strings into the table
SQL = "INSERT into " & table &_
"(FilePath, Filename, Filesize, Artist, Title) VALUES ('" & Replace(strFilepath, "'", "''") _& "','" _
& Replace(strFileName, "'", "''") & "','" _
& Replace(strFileSize, "'", "''") & "','" _
& Replace(strArtist, "'", "''") & "','" _
& Replace(strTitle, "'", "''") & "')"
Cnn.Execute (SQL) 'ERROR OCCURS HERE
Next
This is the code that in the sub that builds the table:
VB Code:
Sub ADOCreateTable()
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.table
' Open the catalog
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source= c:\windows\system\kamo.mdb;"
' Create a new Table object.
With tbl
.Name = categories.txtcategory.Text
' Create fields and append them to the new Table
' object. This must be done before appending the
' Table object to the Tables collection of the
' Catalog.
.Columns.Append "FilePath", adVarWChar
.Columns.Append "FileName", adVarWChar
.Columns.Append "Filesize", adVarWChar
.Columns.Append "Artist", adVarWChar
.Columns.Append "Title", adVarWChar
End With
' Add the new table to the database.
cat.Tables.Append tbl
Set cat = Nothing
End Sub
Any help is extremely appreciated. This doesn't make any sense to me.
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
|