Please help me with my database connection. It says that I have an error with my Insert Statement.

Imports System.Data.OleDb

Public Class Form1

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim connection As OleDb.OleDbConnection

        Dim mydb, mystr As String
        Dim dateFiled = Date.Today
        Dim user = txtUser.Text
        Dim prob = txtProblem.Text
        Dim isolation = txtIsolation.Text
        Dim support = txtSupported.Text

        mystr = ("Provider=Microsoft.JET.OLEDB.4.0;" & _
                     "Data Source=C:\Users\hayasaka\Documents\CSIS\CSIS.mdb")
        connection = New OleDb.OleDbConnection(mystr)

        connection.Open()

        mydb = "INSERT INTO AddReports (date_Filed,filedUser,reported_Problem,isolation,support_By) VALUES (dateFiled,user,prob,isolation,support)"

        Dim run = New OleDb.OleDbCommand

        Try
            run = New OleDbCommand(mydb, connection)
            run.ExecuteNonQuery()
            MsgBox("Connection opened")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
        End Try
    End Sub
End Class

Hi,

You have to use parameters or build SQL Statement accordingly:

connection.Open()
mystr = "INSERT INTO AddReports " _
    & " (date_Filed,filedUser,reported_Problem,isolation, " _
    & " support_By) VALUES (#" & dateFiled & "#,'" & user _
    & "','" & prob & "','" & isolation & "','" & support & "')"            
Dim command As New OleDbCommand(mystr, connection)
command.ExecuteNonQuery()

Regards
Veena

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.