如果
条件..
else 'Try con.open() adp = New oleDbDataAdapter("select * from Login ",con) adp.Fill(dt,"Login") Dim i As Integer For i = 0 To dt.tables(0).Rows.Count - 1 If (cbType.Text = dt.tables(0).Rows(i).Item(1) And txtUname.Text = dt.tables(0).Rows(i).Item(2) And txtPass.Text = dt.tables(0).Rows(i).Item(3)) Then MDIParent1.Show() Exit Sub End If ' Catch ex As Exception Next MsgBox("You Are Not A ValID User!!",MsgBoxStyle.information) End If解决方法 这很简单.
请看下面的代码.
Try 'In this block your program will try to execute your code. 'If it catches any runtime error it will go to the Catch Block straight away without executing the next code in your Try Block. 'If there are no errors then Finally Block will be executed after Try Block. Catch Block will be skipped.Catch 'It will display the errors here. 'So you can use Catch ex as exception. 'If you want to see the errors in MessageBox you can write the below line. 'MessageBox.Show(ex.Message)Finally 'If your program finds errors or not this block will be executed always.End Try
因此,您可以在代码中使用Try … Catch,如下所示:
Dim ValIDUser as Boolean = FalseTry con.open() adp = New oleDbDataAdapter("select * from Login ","Login") Dim i As Integer For i = 0 To dt.tables(0).Rows.Count - 1 If (cbType.Text = dt.tables(0).Rows(i).Item(1) And txtUname.Text = dt.tables(0).Rows(i).Item(2) And txtPass.Text = dt.tables(0).Rows(i).Item(3)) Then ValIDUser = true Exit For End If Next If ValIDUser = True MDIParent1.Show() Else MsgBox("You Are Not A ValID User!!",MsgBoxStyle.information) End IfCatch ex As Exception MessageBox.Show(ex.Message)Finally if con.State = ConnectionState.Open then con.close() End If ValIDUser = FalseEnd Try总结
以上是内存溢出为你收集整理的如何在vb.net中使用try catch并最终阻止?全部内容,希望文章能够帮你解决如何在vb.net中使用try catch并最终阻止?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)