SQL INSERT INTO not inserting into Access DB with no error message

时间:2016-10-20 19:13:35

标签: sql visual-studio ms-access

I have the code inserting logins and data and then its supposed to update the database with INSERT INTO and I have it set up to give me a error message and I am not getting any, but none of them are coming up and when I check the Access file nothing has been added.

 Private Sub AddLog()
    Access.AddParams("@em1", em1)
    Access.AddParams("@em2", em2)
    Access.AddParams("@em3", em3)
    Access.AddParams("@em4", em4)
    Access.AddParams("@em5", em5)
    Access.AddParams("@sit1", sit1)
    Access.AddParams("@sit2", sit2)
    Access.AddParams("@sit3", sit3)
    Access.AddParams("@phys1", phys1)
    Access.AddParams("@phys2", phys2)
    Access.AddParams("@phys3", phys3)
    Access.AddParams("@phys4", phys4)
    Access.AddParams("@phys5", phys5)
    Access.AddParams("@note", note)

    Access.ExecQuery("INSERT INTO EmotionLoginDB (emotion1, emotion2, emotion3, emotion4, emotion5, situation1, situation2, situation3, physical1, physical2, physical3, physical4, physical5, notes) " & _
                     "VALUE (@em1, @em2, @em3, @em4, @em5, @sit1, @sit2, @sit3, @phys1, @phys2, @phys3, @phys4, @phys5, @note); ")

    If Not String.IsNullOrEmpty(Access.exception) Then

    End If
End Sub

And here is the database set up as well.

Imports System.Data.OleDb
Public Class DBControl
Private DBCon As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=StableMe.accdb;")
Private DBCmd As OleDbCommand

Public DBDA As OleDbDataAdapter
Public DBDT As DataTable
Public params As New List(Of OleDbParameter)
Public recordCt As Integer
Public exception As String

Public Sub ExecQuery(query As String)
    recordCt = 0
    exception = ""

    Try
        DBCon.Open()
        DBCmd = New OleDbCommand(query, DBCon)
        For Each p As OleDbParameter In params
            DBCmd.Parameters.Add(p)
        Next
        params.Clear()
        DBDT = New DataTable
        DBDA = New OleDbDataAdapter(DBCmd)
        recordCt = DBDA.Fill(DBDT)
    Catch ex As Exception
        exception = ex.Message
    End Try

    If DBCon.State = ConnectionState.Open Then
        DBCon.Close()
    End If
End Sub

Public Sub AddParams(name As String, value As Object)
    Dim newParam As New OleDbParameter(name, value)
    params.Add(newParam)
End Sub
End Class

I know its a lot and it's probably something simple, but I can't wrap my head around it.

1 个答案:

答案 0 :(得分:1)

the correct syntax is insert into TABLENAME(COLUMN1,COLUMN2,..) VALUES(..,..)