title: vb.net search the sql database to validate a customer account number
body: <p>Group, forgive me for what may be a very simple explanation and answer.  However I'm self teaching myself Visual Basic and very new to this altogether.  So you know, I'm using Visual Studio 2010 Express.</p>
  
  <p>I've created a database that includes a customer records table.  Via the order entry module I'm working on, I want to allow the user to key in a customer account number.  However I need to validate this entry before proceeding with the rest of the program routines.  I THINK I know how to connect to the database, but I'm not sure how to have the user entered number compared against the table to validate the customer number.  Here is what I've written:</p>
  
  <pre><code>            Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection
              Dim dbSource As String = "Data Source = DataDesign.mdf"
              Dim dbProvider As String = "PROVIDER=SQL Server 10.0.5500;"
              Dim ds As New DataSet
              Dim sql As String = "SELECT * FROM AR_CUSTOMERS"
              Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(sql, conn)
              conn.ConnectionString = dbProvider &amp; dbSource 
              Dim search1 As Integer = Integer.Parse(txbCustomerNo.Text)
              Dim cmd1 As SqlCommand = New SqlCommand
              conn.Open()
  </code></pre>
  
  <p>I'm now stuck.  I've defined my "search" (search1), but how do I now tell the program to look through the table to see if there is a matching customer number?</p>
  
  <p>I hate to ask you to help me write the code.  But I'm clueless here and I've not been able to find a good example to help me understand the process and write the code myself.</p>
  
  <p>If you see any syntax errors, don't hesitate to speak up!!</p>
  
  <hr>
  
  <p>Based on some of your answers and further research, I've modified my code.  It now reads:</p>
  
  <pre><code>  Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection
    Dim dbSource As String = "Data Source=.;AttachDbFilename=C:\Users\Don\Documents\DataDesign.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
    Dim dbProvider As String = "PROVIDER=System.Data.SqlClient;"
    Dim ds As New DataSet
    Dim sql As String = "SELECT FROM AR_CUSTOMER"
    Dim da As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(sql, conn)
    conn.ConnectionString = dbProvider &amp; dbSource
    Dim search1 As String = "%" &amp; txbCustName &amp; "%"
    Dim sqlQ1 As String = sql &amp; " WHERE ARC-CUSTOMER-NAME LIKE search1"
    Dim cmd1 As New SqlCommand(sqlQ1, conn)
    conn.Open()
  </code></pre>
  
  <p>Hopefully this syntax (search) looks better and more accurate.  If not, please help me correct it.</p>
  
  <p>Assuming this is correct, what command codes do I need to get the full ARC-CUSTOMER-NAME (and there could potentially be multiple finds) as well as the corresponding ARC-CUSTOMER-NUMBER(s)?  I'm assuming that this data would go into two strings (do I need to "Dim" these to receive the data?) so that it could be put into the checkbox(es) and textbox(es) on the form.</p>
  
  <p>I'm sorry I don't understand this better.  I'm hoping through this the lightbulb in my head will finally come on!!</p>