-4
對於下面顯示的代碼,如果發生錯誤,我將如何使用try/catch塊來處理錯誤?如何在vb.net中使用try和catch塊?
TOTKILO.Text = KILO.Text * TOUCH.Text * 0.01
TextBox10.Text = TextBox9.Text * TextBox8.Text * 0.01
K = Math.Round(Val(TOTKILO.Text) - Val(TextBox10.Text), 5)
TextBox11.Text = TextBox7.Text + K
cmd.CommandType = Data.CommandType.Text
con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\SHOPPROJECT\SHOPPROJECT\shop.mdf;Integrated Security=True;User Instance=True"
con.Open()
If RadioButton1.Checked Then
GOLD = 1
ElseIf RadioButton2.Checked Then
SILVER = 1
End If
If RadioButton3.Checked Then
KGOLD = 1
ElseIf RadioButton4.Checked Then
KSILVER = 1
End If
cmd.CommandText = " INSERT INTO SALES VALUES('" & ComboBox1.Text & " ' , " & SILVER & " ," & GOLD & ",'" & ComboBox2.Text & "'," & KILO.Text & ", " & TOUCH.Text & " ," & TOTKILO.Text & "," & TextBox3.Text & "," & TextBox8.Text & "," & KGOLD & "," & KSILVER & "," & TextBox9.Text & " ," & TextBox10.Text & "," & TextBox11.Text & "," & TextBox12.Text & " , " & TextBox13.Text & ") "
cmd.CommandType = " UPDATE BALANCE SET OBBALANCE = " & TextBox11.Text & " WHERE CUSTOMERNAME = '" & ComboBox1.Text & "' "
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
END SUB
我用VB.Net控制和LINQ to SQL執行所有更新和插入,所以當錯誤發生時我想顯示「請輸入正確的數據」,我該怎麼辦,一旦我抓住一個例外?
請你不要罵的各位 – 2011-03-19 03:07:46
可能重複[如何使用vb.net try和catch(http://stackoverflow.com/questions/ 5359610 /如何使用的嘗試,並趕上在VB網) – 2011-03-19 03:08:01
並且不要張貼同樣的問題兩次! – 2011-03-19 03:09:04