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.