未声明$ exception,由于其保护级别,可能无法访问

时间:2017-08-01 09:39:07

标签: vb.net exception insert

 Public Sub cmdPush_Click(sender As Object, e As EventArgs) Handles cmdPush.Click
        If MessageBox.Show("Are you sure you want to add this record?", "Adding records", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) = DialogResult.Yes Then
            Try
                Call ConntoDB()
                conn.Open()
                Dim cmd2 As SqlCommand
                cmd2 = New SqlCommand
                cmd2.Connection = conn
                cmd2.CommandText = "INSERT INTO studentaccounts (
                Account_Number,
                Tuition_Fee,
                iTuition_Fee,
                Tuition_Fee_DC,
                Bus_Fee,
                iBus_Fee,
                Bus_Fee_DC,
                Full_Name) VALUES (
                @accountnumber,
                @tuitionfee,
                @ituitionfee,
                @tuitionfeedc,
                @busfee,
                @ibusfee,
                @busfeedc,
                @fullname)"
                cmd2.Parameters.AddWithValue("@accountnumber", Me.txtaccount.Text)
                cmd2.Parameters.AddWithValue("@tuitionfee", Me.lbltuitionfee.Text)
                cmd2.Parameters.AddWithValue("@ituitionfee", frmSetupTuitionFee.txttuition.Text)
                cmd2.Parameters.AddWithValue("@tuitionfeedc", frmSetupTuitionFee.txtdiscountrate.Text)
                cmd2.Parameters.AddWithValue("@fullname", Me.lblfullname.Text)
                cmd2.Parameters.AddWithValue("@busfee", Me.lblbusfee.Text)
                cmd2.Parameters.AddWithValue("@ibusfee", frmSetupBusFee.txtbus.Text)
                cmd2.Parameters.AddWithValue("@busfeedc", frmSetupBusFee.txtdiscountratebus.Text)
                cmd2.ExecuteNonQuery()
                MsgBox("Data has been added!")
                Loadlastrow()
                conn.Dispose()
                conn.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            conn.Dispose()
            conn.Close()
            End Try
        Else
        End If
    End Sub

我很无能,因为没有声明$ exception的错误,因为它的保护级别可能无法访问。我错过了什么? 此代码仍然有效,我保存文件去吃午饭,当我回来时,这个问题就出现了。

0 个答案:

没有答案