title: Where I can use dispose? VB.Net
body: <p>Can anyone help where I can put dispose method on this one? so that the variable I use won't be save in the memory. I'm having where should I put or when should I use it.</p>
  
  <p>I tried doing </p>
  
  <blockquote>
    <p>myQuery.Dispose()</p>
  </blockquote>
  
  <p>but I think I'm doing it wrong.</p>
  
  <pre><code>Private Sub btnRegister_Click(sender As Object, e As EventArgs) Handles btnRegister.Click
      mysqlConn.Open()
      If TextBox01.Text = "" Or TextBox02.Text = "" Or TextBox04.Text = "" Or TextBox05.Text = "" Or TextBox06.Text = "" Then
          MsgBox("Please fill in all boxes")
          Exit Sub
  
      Else
  
          sqlCmd = New Odbc.OdbcCommand
          sqlCmd.Connection = mysqlConn
          sqlCmd.CommandType = CommandType.Text
          sqlCmd.CommandText = "select * from tbl_user where username='" &amp; TextBox05.Text &amp; "' Or email='" &amp; TextBox04.Text &amp; "' "
          dr = sqlCmd.ExecuteReader
  
          If dr.HasRows Then
              MsgBox("Username or Email already Exist", MsgBoxStyle.Critical)
          Else
  
              Dim myQuery As String
  
              myQuery = "INSERT INTO tbl_user(firstname, lastname, email, username, password) VALUES ('" &amp; Replace(Trim(TextBox01.Text), "'", "''") &amp; "', '" &amp; Replace(Trim(TextBox02.Text), "'", "''") &amp; "', '" &amp; Replace(Trim(TextBox04.Text), "'", "''") &amp; "', '" &amp; Replace(Trim(TextBox05.Text), "'", "''") &amp; "', '" &amp; Replace(Trim(TextBox06.Text), "'", "''") &amp; "')"
  
  
              sqlCmd = New Odbc.OdbcCommand
              sqlCmd.Connection = mysqlConn
              sqlCmd.CommandText = myQuery
  
              dr = sqlCmd.ExecuteReader
  
              MessageBox.Show("You are now register!", "System", MessageBoxButtons.OK)
              Me.Hide()
              frmMenu.Hide()
              frmLogin.Show()
  
              TextBox01.Text = ""
              TextBox02.Text = ""
              TextBox04.Text = ""
              TextBox05.Text = ""
              TextBox06.Text = ""
          End If
      End If
      mysqlConn.Close()
  End Sub
  </code></pre>