使用vb.net将数据从listview保存到mysql数据库

时间:2015-10-22 11:40:28

标签: mysql vb.net

这是我使用gsm调制解调器将邮件从listview保存到数据库的试用版。 我尝试发送和接收短信窗口应用程序。

保存邮件的代码:

Private Sub btnSaveMessage_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveMessage.Click
    Try
        Connection()
        query = "INSERT INTO tblInbox(index, status, number, date, message) VALUES('" & ListView1.FocusedItem.SubItems(1).Text & "', '" & ListView1.FocusedItem.SubItems(2).Text & "', '" & ListView1.FocusedItem.SubItems(3).Text & "', '" & ListView1.FocusedItem.SubItems(4).Text & "', '" & ListView1.FocusedItem.SubItems(5).Text & "')"
        sqlcmd = New MySqlCommand(query, conn)
        sqlreader = sqlcmd.ExecuteReader

        MsgBox("Message Save")
        conn.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

连接代码

Imports MySql.Data.MySqlClient
Module db_connection
    Public sqlreader As MySqlDataReader
    Public sqlcmd As MySqlCommand
    Public sqladapter As MySqlDataAdapter

    Public conn As New MySqlConnection

    Public Sub Connection()
        Try
            conn = New MySqlConnection
            conn.ConnectionString = "server=localhost; userid=root; password=root; database=thesis"
            conn.Open()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub
End Module

错误

  

您的SQL语法有错误,请查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便使用索引,状态,数字,数据,消息附近的值(' 0& #39;,' REC READ',' + 63907231323','在第1行

任何人都可以帮助我吗?

0 个答案:

没有答案