语法错误插入语句vb.net

时间:2016-03-08 06:06:32

标签: vb.net

请帮我解决这个问题..我对此非常新 我无法将新员工添加到表员工中...每当我尝试添加它时都会显示语法错误插入到语句中

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

1 个答案:

答案 0 :(得分:0)

替换它,

    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