VB 2010 Express连接到数据库microsoft access 2010

时间:2014-09-04 00:38:13

标签: vb.net-2010

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
        Dim sqlquery As String = "INSERT INTO Table1(Customer Name,Address,Contact Number,Type Of Customer)VALUES('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "','" & TextBox4.Text & "')"

        Dim sqlcommand As New OleDbCommand

        With sqlcommand
            .CommandText = sqlquery
            .Connection = con
            .ExecuteNonQuery()
        End With
        MsgBox("ONE RECORD SUCCESFULLY ADDED :)")

    Catch ex As Exception
        MsgBox(ex.ToString)

    End Try
End Sub

有人能帮助我吗?它说INSERT INTO语句中有错误,我不知道为什么。谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

尝试将[]放在包含空格的列名称周围。

([客户名称],地址,[联系电话],[客户类型])

答案 1 :(得分:0)

当你的字段在[your field]中包含空格时很重要,否则它会将其视为两个字段并搜索在这种情况下没有字段的分隔符。

希望我的答案有所帮助。