1

I am using VB to add and search records in a database. I have finished the code in VB but when I execute it, nothing happens to the database.

I have a database called Employee.accdb and a table called tblEmployee consisting of EmployeeID, Title, First Name, Surname, Gender, Date Of Birth and email.

When I do the following query:

INSERT INTO tblEmployee(Title,FirstName,SurName,Gender,DOB,Email)
VALUES("Test","Test","Test","Test","Test","Test")

It works fine. But when I try and run the following code in VB:

Imports System.Data.OleDb
Public Class FormBookAdd
    Public connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Employee.accdb"
    Public conn As New OleDbConnection(connstring)
    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        conn.Open()
        Dim sqlQuery As String = "INSERT INTO tblEmployee(Title,FirstName,SurName,Gender,DOB,Email) VALUES (@Title,@FirstName,@SurName,@Gender,@DOB,@Email)"
        Dim Sqlcommand As New OleDbCommand
        With Sqlcommand
            .CommandText = sqlQuery
            .Parameters.AddWithValue("@Title", txtTitle.Text)
            .Parameters.AddWithValue("@FirstName", txtFirstName.Text)
            .Parameters.AddWithValue("@SurName", txtSurName.Text)
            .Parameters.AddWithValue("@Gender", txtGender.Text)
            .Parameters.AddWithValue("@DOB", txtDOB.Text)
            .Parameters.AddWithValue("@Email", txtEmail.Text)
            .Connection = conn
            .ExecuteNonQuery()
        End With
        conn.Close()
    End Sub

Nothing happens. I don't get any error messages or anything. I don't know what's wrong with it.

Filburt
  • 17,626
  • 12
  • 64
  • 115
test
  • 11
  • 2
  • Are you sure you're not looking at the wrong db [like it happened here](http://stackoverflow.com/q/30112697/205233) (see end of self answer) – Filburt Feb 05 '17 at 22:39
  • Just tried playing with the properties of the database and changed the copy to do not copy which didn't work so I tried copying the database to the bin debug folder and that seems to have worked. Thanks for replying. – test Feb 05 '17 at 23:09
  • If you figured out the answer, make an answer to your own question or close the question. – obl Feb 05 '17 at 23:28
  • "Copy if Newer" is generally the best option. – jmcilhinney Feb 06 '17 at 00:06
  • Hi, how do I close the question? – test Feb 13 '17 at 16:37

0 Answers0