在vb.net语句中插入语法错误

在vb.net语句中插入语法错误,vb.net,Vb.net,请帮我解决这个问题。。我对这个很陌生 我无法将新员工添加到表employee。。每当我尝试添加它时,它都会显示语法错误insert into语句 Public Class AddNewEmployee Dim dr As OleDbDataReader Dim da As OleDbDataAdapter Dim ds As DataSet Dim conn As New OleDbConnection(My.Settings.rayshadatabaseCon

请帮我解决这个问题。。我对这个很陌生 我无法将新员工添加到表employee。。每当我尝试添加它时,它都会显示语法错误insert into语句

Public Class AddNewEmployee

    Dim dr As OleDbDataReader
    Dim da As OleDbDataAdapter
    Dim ds As DataSet
    Dim conn As New OleDbConnection(My.Settings.rayshadatabaseConnectionString)
    Dim cmd As OleDbCommand

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        conn.Open()
        Try
            Dim str As String = "INSERT INTO employee" _
            & "(Employee Name, IC Number, HP Number, Address)" _
            & " Values (" _
            & "'" & txtEmployeeName.Text & "', " _
            & "'" & txtIC_Number.Text & "'," _
            & "'" & txtHP_Number.Text & "'," _
            & "'" & txtAddress.Text & "')"

            cmd = New OleDbCommand(str, conn)
            Dim i As Integer = cmd.ExecuteNonQuery()
            If i > 0 Then
                MessageBox.Show("Record Succesfully added.", "Process Completed", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Else
                MessageBox.Show("Adding failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            conn.Close()
            cmd.Dispose()
        End Try
        frmEmployee.loadR()
        Me.Close()
    End Sub
End Class
取而代之的是,

    Dim str As String = "INSERT INTO employee" _
    & "(Employee Name, IC Number, HP Number, Address)" _
    & " Values (" _
    & "'" & txtEmployeeName.Text & "', " _
    & "'" & txtIC_Number.Text & "'," _
    & "'" & txtHP_Number.Text & "'," _
    & "'" & txtAddress.Text & "')"
有了这个,

Dim str As String = "INSERT INTO employee" _
    & "([Employee Name], [IC Number], [HP Number], [Address])" _
    & " Values (" _
    & "'" & txtEmployeeName.Text & "', " _
    & "'" & txtIC_Number.Text & "'," _
    & "'" & txtHP_Number.Text & "'," _
    & "'" & txtAddress.Text & "')"
谢谢
Manoj

哪一行给出了错误?。不要使用字符串连接,而是使用参数化语句。列名之间尽量不要使用空格。将“EmployeeName”作为列名,而不是“EmployeeName”