Results 1 to 8 of 8

Thread: SQL Insert not adding records to my table!

  1. #1

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

    Angry SQL Insert not adding records to my table!

    I can create the table fine, but the records are not being added to my table. Can someone tell me why? Here's the code:
    VB Code:
    1. 'Create a new table in the Database for the category
    2. Call ADOCreateTable
    3.  
    4. 'connect to the database
    5. Dim Cnn As ADODB.Connection
    6. Dim SQL As String
    7. Set Cnn = New ADODB.Connection
    8. Cnn.Open ConnectionString:="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    9.       "Data Source= c:\windows\system\kamo.mdb;"
    10.  
    11. 'set table = to the category added
    12. table = txtcategory.Text
    13.  
    14. 'Loop through the filelistbox getting info on the files
    15. MusicMaster.File1.Path = txtpath.Text
    16. On Error Resume Next
    17. For x = 0 To MusicMaster.File1.ListCount - 1
    18.     fname = MusicMaster.File1.Path & "\" & MusicMaster.File1.List(x)
    19.     Call ReadMP3(fname, True, True)
    20.    
    21. 'Store the info as strings
    22.     strFilepath = fname
    23.     strFileName = MusicMaster.File1.List(x)
    24.     strFileSize = FileLen(fname)
    25.     strArtist = GetMP3Info.Artist
    26.     strTitle = GetMP3Info.Songname
    27.     strAlbum = GetMP3Info.Album
    28.     strTrack = GetMP3Info.Track
    29.     strFrequency = GetMP3Info.Frequency
    30.     strBitrate = GetMP3Info.Bitrate
    31.     strLength = GetMP3Info.Duration
    32.    
    33.    
    34. 'Use SQL to insert the information in the strings into the table
    35. SQL = "INSERT into " & table & " (Filepath,Filename,Filesize,Artist, _
    36. Title,Album,Frequency,Bitrate,Length, _
    37. Track#)VALUES ('" & strFilepath & "','" & _
    38.  strFileName & "','" & strFileSize & "','" & _
    39. strArtist & "','" & strTitle & _
    40. "','" & strAlbum & "','" & strTrack & _
    41.  "','" & strFrequency & "','" & strBitrate & _
    42.  "','" & strLength & "')"
    43. Cnn.Execute (SQL)
    44.  
    45. Next 'Loop through getting info and adding a record for each item in the filelistbox.

  2. #2
    Hyperactive Member DKCK's Avatar
    Join Date
    Dec 2000
    Location
    United States
    Posts
    329
    Humm. What is your error? Also I see the connection object but no recordset object.

  3. #3
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    he doesnt need a recordset object

  4. #4
    Hyperactive Member DKCK's Avatar
    Join Date
    Dec 2000
    Location
    United States
    Posts
    329
    True. He doesn't say if there is an error. Could be the database has a password. Could be the SQL is wrong. Could be just about anything.

  5. #5

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

    There is no error

    I don't get an error, and the database I created is not pw protected. I'm guessing it's a problem with my SQL. The values I am entering are strings. Can someone give me some help with the SQL part? I thought the code seemed pretty clear to understand. Let me know if you need more info.

  6. #6
    Hyperactive Member DKCK's Avatar
    Join Date
    Dec 2000
    Location
    United States
    Posts
    329
    The fields you are trying to insert could be the wrong size and/or type. Double check that. You can also try printing out your SQL string, copying the text, and moving it over to Access. You can then test the SQL statement using a query and see if it is working.

  7. #7
    Hyperactive Member dRAMmer's Avatar
    Join Date
    Oct 2001
    Location
    strangelans
    Posts
    463
    now ive found sum1 with d same problm.

    but mine do has an error and sumtimes dont. the problem is the string, or the vars that contains the string has {'} in it. and sometimes {.} or simply punctuations. when i tried to omit those punctuations from the source, strings/vars, the Execute method workd fine.

    so our question might be, or should be...

    what is the correct INSERT INTO statement if the string contains punctuations?
    live, code and die...

  8. #8
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    ahhh, i had this same problem a while back, had me totally stumped all day! i went the dodgey option and just didnt allow any '

    hehe

    but what u have to do is use forward slash then the '

    like

    /'

    means '


    i THINK, someone told me that a while back, i never used it, so i could be totally wrong, worth a try though.
    (and if u want a forward slash use //)

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