tags:

views:

63

answers:

1

i have a problem in inserting the listbox value into mysql database in vb 2008 i.e

if i select a video file i.e D:\videos\video1.mpg and add a msgbox() event before inserting into data base it shows the exact path i.e D:\videos\video1.mpg but when i check my database it shows me as D:videosvideo1.mpg how can i solve that... here is my code

 Dim check As String
    Dim check_cmd As New MySqlCommand
    Dim checklist As New MySqlDataAdapter
    Dim listfile As String
    Dim time As String
    time = DateAndTime.Now

    For L = 0 To bee_shed.Items.Count - 1
                listfile = bee_shed.Items.Item(L)

                check = "INSERT INTO schedule(id, listname, videofile, videoduration, videotime) VALUES('', '', '" & listfile & "', '' , '" & time & "')"
                check_cmd.Connection = con
                check_cmd.CommandText = check
                checklist.SelectCommand = check_cmd
                check_cmd.ExecuteNonQuery()
                MsgBox(listfile)
            Next
+2  A: 

You're concatenating raw SQL statements and not escaping the backslash.

You must use parameters.

For example:

check_cmd.Connection = con
check_cmd.CommandText = "INSERT INTO schedule(id, listname, videofile, videoduration, videotime) VALUES('', '', ?filename, '' , ?time)"

For L = 0 To bee_shed.Items.Count - 1
    listfile = bee_shed.Items.Item(L)

    check_cmd.Parameters.Clear()
    check_cmd.Parameters.Add("filename", MySqlDbType.VarChar, 80).Value = listfile
    check_cmd.Parameters.Add("time", MySqlDbType.Something).Value = time
    check_cmd.ExecuteNonQuery()
Next
SLaks