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

Recommended Answers

All 2 Replies

I pickd up your code, all fine
So, what does not work in your case

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|

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.