0

No ERRORS query is executed perfectly but no data stored what could be wrong?

my database is employee with id, first_name, middle_name, last_name fields
id is auto number the rest is short text

I'm using ms access.

Imports System.Data.OleDb

Public Class AccountReg

    Dim dbProvider As String

    Dim dbSource As String

    Dim connString As String

    Dim myConnection As OleDbConnection = New OleDbConnection



Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"

        dbSource = "Data Source=|DataDirectory|\PIA-AMS.accdb"

        connString = dbProvider & dbSource

        myConnection.ConnectionString = connString

        myConnection.Open()

        Dim str As String

        str = "INSERT INTO employee (first_name, middle_name, last_name) VALUES (?,?,?)"

        Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)

        cmd.Parameters.Add(New OleDbParameter("first_name", CType(TextBox1.Text, String)))

        cmd.Parameters.Add(New OleDbParameter("middle_name", CType(TextBox2.Text, String)))

        cmd.Parameters.Add(New OleDbParameter("last_name", CType(TextBox3.Text, String)))


        Try

            cmd.ExecuteNonQuery()

            cmd.Dispose()

            myConnection.Close()

            TextBox1.Clear()

            TextBox2.Clear()

            TextBox3.Clear()

        Catch ex As Exception

            MsgBox(ex.Message)

        End Try

    End Sub

End Class
2
Contributors
2
Replies
16
Views
2 Years
Discussion Span
Last Post by Erald
0

I already solved the problem but it is not what I want. I found out that the problem is
dbSource = "Data Source=|DataDirectory|\PIA-AMS.accdb"

I change it to the full directory of the database. something is wrong with |DataDirectory|

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.