在visual basic 2008中插入列表框值的问题

时间:2010-02-28 22:54:05

标签: vb.net

我在将vb 2008中的列表框值插入mysql数据库时遇到了问题,即

如果我选择一个视频文件,即D:\ videos \ video1.mpg并在插入数据库之前添加一个msgbox()事件,它会显示确切的路径,即D:\ videos \ video1.mpg,但是当我检查我的数据库时它显示我为D:videosvideo1.mpg我该如何解决... 这是我的代码

 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

1 个答案:

答案 0 :(得分:2)

您正在连接原始SQL语句而不是转义反斜杠。

必须使用参数。

例如:

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