我需要帮助来获取输入的信息并将其插入到简单的Access DB中。仅使用三个文本框,DB只有三列。当我选择写入数据库的按钮时,遇到一条消息,指出“ ExecuteNonQuery连接属性尚未初始化”。代码如下,在寻求帮助来确定查询未插入Access DB的问题。
If txtFirstNumber.Text = "" Or txtSecondNumber.Text = "" Then
MsgBox("Please fill the details")
Else
Try
Using conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Shawn\Desktop\Dave\CertificationCourse-AMU\ENTD461 - Advanced VB.Net\wk6\Week6ExerciseDB.accdb;")
conn.Open()
Dim sql As New OleDbCommand("INSERT INTO Mathops[FirstNumber],[SecondNumber],[Results] Values (@FirstNumber, @SecondNumber, @Results)")
With sql.Parameters
.AddWithValue("@FirstNumber", txtFirstNumber.Text)
.AddWithValue("@SecondNumber", txtSecondNumber.Text)
.AddWithValue("@Result", txtResult.Text)
End With
sql.ExecuteNonQuery()
MessageBox.Show("Week6ExerciseDB Successfully Updated", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Information)
sql.Dispose()
conn.Close()
txtFirstNumber.Text = ""
txtSecondNumber.Text = ""
txtResult.Text = ""
End Using
Catch ex As Exception
MessageBox.Show(ex.Message, "ERROR12", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End If