Results 1 to 3 of 3

Thread: SQL Insert Statement usage...

  1. #1

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

    SQL Insert Statement usage...

    Ok, I use the following code to get info about mp3 files and then store as strings. Now I want to take the strings and use SQL to INSERT them into a table (add rows). The "Call ADOCreateTable" in the code creates a new table in the db. You should be able to see what I want to do by looking at the below code. I tried just typing INSERT and VALUE SQL commands, but it says it needs to be set = to something. Do I need to declare I'm using SQL first or something?
    VB Code:
    1. Private Sub Command2_Click()
    2. Dim x As Integer
    3. Dim strFilepath As String, strFileName As String, _
    4. strFileSize As String, strArtist As String, _
    5. strTitle As String, strAlbum As String, strTrack As String, _
    6. strFrequency As String, strBitrate As String, _
    7. strLength As String
    8.  
    9.  
    10.  
    11. lstCategories.AddItem txtcategory.Text
    12. Call ADOCreateTable  'create the new table in the db
    13.  
    14. For x = 0 To File1.ListCount - 1    'loop through the filelistbox
    15.     fname = File1.Path & "\" & File1.List(x)
    16.     ReadMP3 fname, True, True
    17.    
    18.     strFilepath = fname              'store the info as strings
    19.     strFileName = File1.List(x)
    20.     strFileSize = FileLen(fname)
    21.     strArtist = GetMP3Info.Artist
    22.     strTitle = GetMP3Info.Songname
    23.     strAlbum = GetMP3Info.Album
    24.     strTrack = GetMP3Info.Track
    25.     strFrequency = GetMP3Info.Frequency
    26.     strBitrate = GetMP3Info.bitrate
    27.     strLength = GetMP3Info.Duration
    28.    
    29.     '------------------------------------------------------------------------
    30.     'Here is where I want to add all the strings into the table
    31.     '------------------------------------------------------------------------
    32.      Next    'do this for every file in the filelistbox
    33.  
    34.  
    35. Call WriteTextFile   'Updates entries in category combobox
    36. End Sub

  2. #2

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

    Here's the ADOCreateTable code......

    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.       .Columns.Append "Album", adVarWChar
    23.       .Columns.Append "Frequency", adVarWChar
    24.       .Columns.Append "Bitrate", adVarWChar
    25.       .Columns.Append "Length", adVarWChar
    26.       .Columns.Append "Track#", adVarWChar
    27.      
    28.    End With
    29.  
    30.    ' Add the new table to the database.
    31.    cat.Tables.Append tbl
    32.  
    33.    Set cat = Nothing
    34.    
    35.    
    36.  
    37. End Sub

  3. #3
    Addicted Member Pickler's Avatar
    Join Date
    May 2001
    Location
    nffanb
    Posts
    248
    You can add something along these lines.
    VB Code:
    1. Dim Cnn As ADODB.Connection
    2. Dim SQL As String
    3. Set Cnn = New ADODB.Connection
    4. Cnn.Open ConnectionString:="Provider=Microsoft.Jet.OLEDB.4.0;" & _
    5.       "Data Source= c:\windows\system\kamo.mdb;"
    6.  
    7. SQL = "INSERT into Table (field1,field2,field3 etc..) VALUES ('" & strTitle & "','" & "etc..."
    8. Cnn.Execute SQL

    A couple of notes, you can declare the connection object so it can be used by both functions.
    and just be careful with your SQL statement that you have apostrophes etc.. in the right spot.

    Hope it helps

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