title: How do I use try catch and finally block in vb.net?
body: <p>Below is the code in which  I wanted to use try catch and finally block But I am unable to do the same , I am new in programming, Please help me to introduce try catch and finally block in the below code in vb.net, Also help to code for finally block where I will be checking whether connection is open or not , I Connection is open then it should be closed in finally block but after checking .
  If</p>
  
  <p>conditions..</p>
  
  <pre><code>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
  </code></pre>