Mriggyoggy
Mriggyoggy

Reputation: 11

Error in INSERT INTO statement vb.net

I am trying to insert data into an Access database and for some unknown reason when I try to insert I get the error:

ERROR in INSERT INTO statement.

The weird thing is I have other forms using this technique but they work fine.

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

Upvotes: 1

Views: 73

Answers (1)

vercelli
vercelli

Reputation: 4767

Date is a reserved word in Access. You might be facing this error.

Upvotes: 1

Related Questions