title: calling a VB.net Function for SQL recordset
body: <p>Beginner here</p>
  
  <p>I have the following code which I would like to call using a button called findCustomerBTN</p>
  
  <pre><code>   Public Function Execute(ByVal sqlQuery As String) As ADODB.Recordset
  
      If SecuritySSPIchkbx.Checked Then
          chk = "TRUE"
      Else chk = "FALSE"
      End If
      builder.DataSource = ServerBox.Text
      builder.InitialCatalog = DatabaseBox.Text
      builder.UserID = Username.Text
      builder.Password = Password.Text
      builder.IntegratedSecurity = chk
      MessageBox.Show(builder.ConnectionString)
  
      Using sqlConnection1 As New SqlConnection(builder.ConnectionString)
  
          sqlConnection1.Open()
          Try
              command = New SqlCommand(sqlQuery, sqlConnection1)
              adapter.SelectCommand = command
              adapter.Fill(ds, "Create DataView")
              adapter.Dispose()
              command.Dispose()
              sqlConnection1.Close()
  
              dv = ds.Tables(0).DefaultView
              DataGridView1.DataSource = dv
  
  
  
          Catch ex As Exception
              MsgBox(ex.ToString)
          End Try
      End Using
  
  End Function
  </code></pre>
  
  <p>How do I call this function:</p>
  
  <pre><code>     Private Sub findCustomerBTN_Click(sender As Object, e As EventArgs) Handles
  sqlquery = "Select * from customers where name = 'Smith'"
  call function?
      End Sub
  </code></pre>
  
  <p>I have googled but I can't wrap my head around how a function works any pointers to help me understand would be great thanks</p>