2015-09-24 54 views
-4

我在這段代碼中有錯誤請 我需要這個在學校它的一個小組項目,但我只做這個,因爲他們不知道如何編碼,所以我參與做這個程序,即時通訊初學者在VB中,希望大家理解,謝謝:)OleDbException was unhandled [新手在這裏]

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 
+3

有相當代碼的一部分,其中的大部分顯然是不相關的。我們不應該通過不相關的代碼來研究,因爲你無法研究需要發佈什麼,什麼不發佈。只發布相關代碼,並指出錯誤發生的位置。這裏的人很樂意幫忙,但我們不想浪費時間去處理那些你已經知道並能告訴我們的事情。 – jmcilhinney

回答

0

這意味着你有沒有處理,你應該處理異常甚至會告訴你一個錯誤,還可以幫助你一個可能的例外你的代碼出了什麼問題:)

你如何處理異常?在你使用OleDb的任何地方使用OleDB與OleDB一起使用OleDB的代碼,你應該嘗試/捕獲它。當你知道你的代碼工作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,以及這是不是必要的,但它得到所有的OleDb的東西,在一個try/catch

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 
相關問題