INSERT INTO语句vb.net出错

时间:2016-06-23 09:49:56

标签: sql vb.net ms-access

我正在尝试将数据插入Access数据库,当我尝试插入时出于某种未知原因我得到了错误:

  

INSERT INTO语句中的错误。

奇怪的是,我有其他形式使用这种技术,但它们工作正常。

Private Sub SetActivityBtn_Click(sender As Object, e As EventArgs) Handles SetActivityBtn.Click
    conn.Open()
    Dim SqlQuery As String = "INSERT INTO PlannedActivity (ActivityID,Date) VALUES (@ActivityID,@Date)"
    MsgBox(SqlQuery)
    Dim SqlCommand As New OleDbCommand
    With SqlCommand
        .CommandText = SqlQuery
        .Parameters.AddWithValue("@ActivityID", EnterActvityIDTxtBox.Text)
        .Parameters.AddWithValue("@Date", SetActivityDateTxtBox.Text)
        .Connection = conn
        .ExecuteNonQuery()
    End With

    Dim SqlqueryFetch As String = "SELECT ID FROM PlannedActivity WHERE ActivityID = '" & EnterActvityIDTxtBox.Text & "' "

    Dim da As OleDbDataAdapter = New OleDbDataAdapter(SqlqueryFetch, conn)
    Dim ds As DataSet = New DataSet
    da.Fill(ds, "ID")
    Dim dt As DataTable = ds.Tables("ID")


    ActIDIsTxtBox.Text = (ds.Tables("ID").Rows(0).Item(0))

    conn.Close()

    EnterActvityIDTxtBox.Clear()
    SetActivityDateTxtBox.Clear()
    MsgBox("Activity has been Set sucessfully!")

End Sub

1 个答案:

答案 0 :(得分:1)

日期是Access中的reserved word。您可能会遇到此error