我正在为我的学位项目开发的 VB 系统遇到这个问题。
我在列表中没有任何错误,但我有一条弹出消息显示“您的应用程序中发生了未处理的异常。如果您单击继续,应用程序将忽略继续尝试......”
弹出窗口显示后,exe挂起并退出。
这是代码。该代码旨在接受有关 Admin 的少量详细信息,并将其保存在名为 CQFOS 的 Microsoft Access DB 中,并带有名为 adminrecords 的表。
Imports System.Data.OleDb
Imports System.Configuration
Public Class adminadd
'must put everytime, global bro
Dim con As New OleDbConnection
Dim cmd As New OleDbCommand
Private Sub addadmin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addadmin.Click
Dim TA As New CQFOSDataSet1TableAdapters.adminrecordsTableAdapter
Dim cmd As New OleDbCommand
Dim con As New OleDbConnection
'Dim yourconnection As String = ConfigurationManager.ConnectionStrings("yourConnectionString").ConnectionString()
Dim yourconnection As String = ConfigurationManager.ConnectionStrings("yourconnectionstring").ConnectionString
'con = New OleDbConnection(yourconnectionString)
con = New OleDbConnection(yourconnection)
cmd.CommandType = CommandType.Text
Dim connectionString As String = ConfigurationManager.ConnectionStrings("CQFOSConnectionString").ConnectionString
con = New OleDbConnection(connectionString)
cmd.CommandType = CommandType.Text
cmd.CommandText = "INSERT INTO adminrecords (AdminID,Name,DOB,Gender,Address,PhoneNo,Email) VALUES (@AdminID, @Name,@DOB,@Gender,@Address,@PhoneNo,@Email)"
cmd.Parameters.AddWithValue("@AdminID", adminidtxt.Text)
cmd.Parameters.AddWithValue("@Name", nametxt.Text)
cmd.Parameters.AddWithValue("@DOB", dobtxt.Text)
cmd.Parameters.AddWithValue("@Gender", gendertxt.Text)
cmd.Parameters.AddWithValue("@Address", addtxt.Text)
cmd.Parameters.AddWithValue("@PhoneNo", cnotxt.Text)
cmd.Parameters.AddWithValue("@Email", emailtxt.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 adminrecords"
If RowsAffected = 1 Then
MsgBox("New Record is saved.", MsgBoxStyle.OkOnly, "CQFOS")
End If
con.Close()
End Sub
End Class
任何帮助表示赞赏。先感谢您。