代碼如下:已經更新成功了,但是卻沒有提示。第一個msgbox在為空時候可以提示的。就是在TRY裡面的不會提示。 換成MESSAGEBOX.SHOW也不行。
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If TextBox8.Text = "" Or TextBox9.Text = "" Or MaskedTextBox1.Text = "" Then
MsgBox("Please input above")
End If
Dim mycn As New SqlClient.SqlConnection
Dim mycom As New SqlClient.SqlCommand
mycn.ConnectionString = "Data Source=192.168.0.215;Initial Catalog=blue;uid=sa;pwd=Wks123"
mycom.CommandText = " Update KnitC set Cleaner ='" & MaskedTextBox1.Text & "' where substring(filenm,1,4)='" & TextBox8.Text & "' and substring(filenm,charindex('.',FileNM)+1,LEN(fileNM)-charindex('.',fileNM))='" & TextBox9.Text & "'"
mycom.Connection = mycn
Try
mycn.Open()
Dim mysqlreader As Data.SqlClient.SqlDataReader = mycom.ExecuteReader
If mycom.ExecuteNonQuery > 0 Then
MsgBox("Save success")
Else
MsgBox("Save Fail")
End If
Catch ex As Exception
Finally
mycn.Close()
End Try
End Sub
直接把判斷去掉 ,放到 catch ex as exception 裡面 了。。實在是沒有其他辦法。。。說判斷裡面根本就不執行。