基于VB的系统出现未处理的异常错误,

时间:2013-07-15 10:18:15

标签: vb.net ms-access

我正在为我的学位项目开发的VB系统遇到这个问题。

我在列表中没有任何错误但是我弹出一条消息,显示“您的应用程序中发生了未处理的异常。如果您单击继续,应用程序将忽略尝试继续....”< / p>

弹出窗口后,exe挂起并退出。

这是代码。该代码旨在接受有关Admin的一些详细信息,并将其保存在名为adminrecords的表中名为CQFOS的Microsoft Access数据库中。

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

感谢任何帮助。提前谢谢。

1 个答案:

答案 0 :(得分:0)

cmd.CommandText = "INSERT INTO adminrecords   
(AdminID,Name,DOB,Gender,Address,PhoneNo,Email) VALUES
(@AdminID, @Name,@DOB,@Gender,@PhoneNo,@Address, @Email)"

你的PhoneNo和地址参数是错误的。