title: SQL and VB.NET : SELECT query using data in textbox
body: <p>I'm trying to create a search, where the SQL query depends on a radio button and a textbox.</p>
  
  <pre><code>SELECT * FROM [Sales] WHERE (text in radio button) = (text in textbox)
  </code></pre>
  
  <p>How can I implement this?</p>
  
  <p>Below is my full code.</p>
  
  <pre><code>Protected Sub btnSearch_Click(sender As Object, e As ImageClickEventArgs) Handles btnSearch.Click
      If radClient.Checked = True Then
          Dim connection As New OleDb.OleDbConnection
          Dim provider As String
          Dim source As String
          provider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
          source = "Data Source=|DataDirectory|DeltaOneMDB.mdb"
          connection.ConnectionString = provider &amp; source
          GridView1.Visible = False
          connection.Open()
          SqlDataSource3.SelectCommand = "SELECT * FROM Sales WHERE ClientID = '" &amp; txtSearch.Text &amp; "'"
          connection.Close()
      ElseIf radItem.Checked = True Then
          Dim connection As New OleDb.OleDbConnection
          Dim provider As String
          Dim source As String
          provider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
          source = "Data Source=|DataDirectory|DeltaOneMDB.mdb"
          connection.ConnectionString = provider &amp; source
          GridView1.Visible = False
          connection.Open()
          SqlDataSource3.SelectCommand = "SELECT * FROM Sales WHERE ItemID = '" &amp; txtSearch.Text &amp; "'"
          connection.Close()
      ElseIf radUser.Checked = True Then
          Dim connection As New OleDb.OleDbConnection
          Dim provider As String
          Dim source As String
          provider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
          source = "Data Source=|DataDirectory|DeltaOneMDB.mdb"
          connection.ConnectionString = provider &amp; source
          GridView1.Visible = False
          connection.Open()
          SqlDataSource3.SelectCommand = "SELECT * FROM Sales WHERE UserID = '" &amp; txtSearch.Text &amp; "'"
          connection.Close()
      ElseIf radUser.Checked = False And radClient.Checked = False And radItem.Checked = False Then
          ErrorLabel.Text = "Error: You have not chosen a search criteria."
      End If
  End Sub
  </code></pre>
  
  <p>The table, textbox and radio button are all on the same form. I'm using Microsoft Visual Studio 2012 for Web, and trying to change the data source for a GridView object on the form. However, I keep getting the error:</p>
  
  <p><em><strong>The ConnectionString property has not been initialized.</em></strong></p>
  
  <p>Apologies for not giving my code earlier.</p>
  
  <p>Thank you!</p>