执行查询时没有错误,但没有存储数据。可能有什么不对?
我的数据库是具有id,first_name,middle_name,last_name字段的员工。 id是自动编号,其余是短文本
我正在使用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