晚上好程序员。我正在做我最后一年的项目,并且正在做一个基于 VB.net 和 Access 数据库的食品订购系统。当我调试我的应用程序时,我一直出现这个错误,
System.Data.dll 中出现“System.Data.OleDb.OleDbException”类型的第一次机会异常附加信息:INSERT INTO 语句中的语法错误。
这是我正在处理的代码的副本。此代码遵循输入管理员详细信息的类似代码。此表单中的此特定代码旨在接受用于登录系统的管理员 ID 和密码。
Imports System.Data.OleDb
Imports System.Configuration
Public Class adminadd2
'must put everytime, global bro
Dim con As New OleDbConnection
Private Sub save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save.Click
Dim TA As New CQFOSDataSet1TableAdapters.adminloginTableAdapter
Dim cmd As New OleDbCommand
Dim con As New OleDbConnection
'Dim yourconnection As String = ConfigurationManager.ConnectionStrings("yourconnectionstring").ConnectionString
'con = New OleDbConnection(yourconnection)
'cmd.CommandType = CommandType.Text
Dim connectionString As String = ConfigurationManager.ConnectionStrings("Mark1.My.MySettings.CQFOSConnectionString").ConnectionString
con = New OleDbConnection(connectionString)
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT INTO adminlogin(Username,Password) VALUES(@Username,@Password)"
cmd.Parameters.AddWithValue("@Username", adminid.Text)
cmd.Parameters.AddWithValue("@Password", adminpass.Text)
cmd.Connection = con
Dim RowsAffected As Integer
con.Open()
'rowaffected returns the number or row affected
RowsAffected = cmd.ExecuteNonQuery()
Dim selectQuery As String = "Select FROM adminlogin"
If RowsAffected = 1 Then
MsgBox("New Admin is saved. Login Using your credentials.", MsgBoxStyle.OkOnly, "CQFOS")
End If
con.Close()
Me.Hide()
adminaccess.Show()
End Sub
End Class