“ID”附近的语法不正确

时间:2017-07-03 05:02:07

标签: visual-studio-2010 ssms

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
    cn = New SqlConnection
    cn.ConnectionString = "Data Source=LAPTOP-VLPOS8UG;Initial Catalog=FAMS;Integrated Security=True"
    Try
        cn.Open()
        Dim query As String
        query = "INSERT INTO Master (Asset ID, Asset Category, Department, Brand/Make, Product Serial No, Purchase Date, Purchase Order Date, Installation Date, Purchase Cost, Depriciation Rate, Vendor Code, Warranty Details, Processor, RAM, HDD, Operating System, Application/Software, Note, Asset Name, Status)" + "VALUES ('" & Asset_IDTextBox.Text & "','" & Asset_CategoryComboBox.Text & "','" & DepartmentComboBox.Text & "','" & Brand_MakeTextBox.Text & "','" & Product_Serial_NoTextBox.Text & "','" & Purchase_DateDateTimePicker.Text & "','" & Purchase_Order_DateDateTimePicker.Text & "','" & Installation_DateDateTimePicker.Text & "','" & Purchase_CostTextBox.Text & "','" & Depriciation_RateTextBox.Text & "','" & Vendor_CodeComboBox.Text & "','" & Warranty_DetailsComboBox.Text & "','" & ProcessorComboBox.Text & "','" & RAMComboBox.Text & "','" & HDDComboBox.Text & "','" & Operating_SystemComboBox.Text & "','" & Application_SodtwareTextBox.Text & "','" & NoteTextBox.Text & "','" & Asset_NameTextBox.Text & "','" & StatusComboBox.Text & "')"
        cmd = New SqlCommand(query, cn)
        dr = cmd.ExecuteReader

        MessageBox.Show("Data Saved")
        cn.Close()
    Catch ex As SqlException
        MessageBox.Show(ex.Message)
    Finally
        cn.Dispose()

    End Try

End Sub

1 个答案:

答案 0 :(得分:0)

由于您使用标记了问题,我认为您的RDBMS是SQL Server。

您的表中有多个列名称的空格;尝试在包含空格的列名称周围使用方括号:

query = "INSERT INTO Master ([Asset ID], [Asset Category],...