我正在使用VB在数据库中添加和搜索记录。我已经在VB中完成了代码,但是当我执行它时,数据库没有任何反应。
我有一个名为Employee.accdb的数据库和一个名为tblEmployee的表,包括EmployeeID,Title,First Name,Surname,Gender,Birth and Marb。
当我执行以下查询时:
INSERT INTO tblEmployee(Title,FirstName,SurName,Gender,DOB,Email)
VALUES("Test","Test","Test","Test","Test","Test")
工作正常。但是当我尝试在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
什么都没发生。我没有收到任何错误消息或任何东西。我不知道它有什么问题。