OleDbException未处理[新手在这里]

时间:2015-09-24 00:55:49

标签: vb.net

请在此代码中出错 我需要在学校这是一个小组项目,但我只是这样做,因为他们不知道如何编码,所以我参与做这个程序,我在vb的begginer,我希望你明白,谢谢你:)

Imports System.Data.OleDb
Imports System
Imports System.Data
Imports System.Data.SqlClient

Public Class Form9

    Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'FoodDataSet.Table1' table. You can move, or remove it, as needed.

        Table1BindingSource.AddNew()


    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        If RadioButton1.Checked = True Then
            TextBox1.Text = ("Burger P 12")
        ElseIf RadioButton1.Checked = False Then
            TextBox1.Text = ("Choose Your Order!")

        End If
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        If RadioButton2.Checked = True Then
            TextBox1.Text = ("Cheese Burger = P 15")
        ElseIf RadioButton2.Checked = False Then
            TextBox1.Text = ("Choose Your Order!")
        End If
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        If RadioButton3.Checked = True Then
            TextBox1.Text = ("Ham Burger = P 15")
        ElseIf RadioButton3.Checked = False Then
            TextBox1.Text = ("Choose Your Order!")
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Hide()


    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        If RadioButton4.Checked = True Then
            TextBox2.Text = ("Potato = P 10")
        ElseIf RadioButton4.Checked = False Then
            TextBox2.Text = ("Choose Your Order!")
        End If
    End Sub

    Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
        If RadioButton5.Checked = True Then
            TextBox2.Text = ("Piatos = P 12")
        ElseIf RadioButton5.Checked = False Then
            TextBox2.Text = ("Choose Your Order!")
        End If
    End Sub

    Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
        If RadioButton6.Checked = True Then
            TextBox2.Text = ("Potato Fries = P 15")
        ElseIf RadioButton6.Checked = False Then
            TextBox2.Text = ("Choose Your Order!")
        End If
    End Sub

    Private Sub RadioButton11_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton11.CheckedChanged
        If RadioButton11.Checked = True Then
            TextBox3.Text = ("Coke = P 10")
        ElseIf RadioButton11.Checked = False Then
            TextBox3.Text = ("Choose Your Order!")
        End If
    End Sub

    Private Sub RadioButton8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton8.CheckedChanged
        If RadioButton8.Checked = True Then
            TextBox3.Text = ("Sprite = P 10")
        ElseIf RadioButton8.Checked = False Then
            TextBox3.Text = ("Choose Your Order!")
        End If
    End Sub

    Private Sub RadioButton9_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton9.CheckedChanged
        If RadioButton9.Checked = True Then
            TextBox3.Text = ("Royal = P 10")
        ElseIf RadioButton9.Checked = False Then
            TextBox3.Text = ("Choose Your Order!")
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim con As OleDbConnection
        Table1BindingSource.AddNew()
        MessageBox.Show("Your Orders in ongoing,Kindly Prepare your money and wait your order, Thank you!")

        Me.Validate()
        Me.Table1BindingSource.EndEdit()
        con = New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0;Data Source=C:\Documents and Settings\WinXP\Desktop\LoadTest HP\WindowsApplication1\Food.mdb")

        Me.Table1TableAdapter.Update(Me.FoodDataSet.Table1)



    End Sub
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Table1BindingSource.RemoveCurrent()

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()

    End Sub

    Private Sub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton7.CheckedChanged

    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub

    Private Sub Button4_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Form10.Show()
        Me.Close()

    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

这意味着你有一个可能的例外,你应该处理异常,甚至会出现错误,这可以进一步帮助你弄清楚你的代码有什么问题:)

你如何处理异常?在使用OleDb的任何地方使用OleDB和try / catch的包装代码你应该尝试/捕获它...当你知道你的代码100%工作时,删除try / catch。

喜欢这样..

Try
  con = New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0;Data Source=C:\Documents and Settings\WinXP\Desktop\LoadTest HP\WindowsApplication1\Food.mdb")
Catch ex as OleDbException
  Msgbox ex.ToString()
End Try

我会在你声明OleDbConnection的地方进行包装,但这不是必需的,但它会在try / catch中获取所有OleDb内容

Try
        Dim con As OleDbConnection
        Table1BindingSource.AddNew()
        MessageBox.Show("Your Orders in ongoing,Kindly Prepare your money and wait your order, Thank you!")

        Me.Validate()
        Me.Table1BindingSource.EndEdit()
        con = New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0;Data Source=C:\Documents and Settings\WinXP\Desktop\LoadTest HP\WindowsApplication1\Food.mdb")
Catch ex as OleDbException
        Msgbox ex.ToString()
End Try