title: VB.net WHERE Statement for MySQL
body: <p>Good evening everyone. I ran into a problem that has me somewhat stumped. I am converting over to MySQL from Access and it seems that some of the Syntax is different for a MySQL Query. What I am doing is an operator selects a Client form a "ComboBox" which is populated from records in the "Client" table. I got that done with no problems. When the user selects a client, another combobox gets populated with data from the table "Lines". The table "Lines" has 2 columns Client and Line. I was trying to get each line WHERE Client = LEXAR. Any thoughts or ideas?</p>
  
  <p>I figured it would be something like:</p>
  
  <pre><code>"SELECT * FROM Lines WHERE Client=LEXAR"
  
  or
  
  "SELECT * FROM Lines WHERE(client = @LEXAR)"
  
  or
  
  "SELECT * FROM Lines WHERE(client = '@LEXAR')"
  
  or
  
  "SELECT * FROM Lines WHERE client LIKE LEXAR)"
  
  or
  
  
  
  "SELECT * FROM ``Lines``WHERE ``Client``='LEXAR')"
  
  or
  
  "SELECT * FROM Lines WHERE Client ='LEXAR')"
  </code></pre>
  
  <p>but none work. Here is my code:</p>
  
  <pre><code>Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM Lines WHERE(client = @LEXAR)", con)
          Dim dt As DataTable = New DataTable()
  
          Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter(sql)
          DataAdapter1.Fill(dt)
  
  
          If dt.Rows.Count &gt; 0 Then
              ComboBox1.DataSource = dt
              ComboBox1.DisplayMember = "Line"
          End If
          con.Close()
  </code></pre>
  
  <p>These are the errors:</p>
  
  <pre><code>Fatal error encountered during command execution.
  </code></pre>
  
  <p>and</p>
  
  <pre><code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Lines WHERE client =  LEXAR)' at line 1
  </code></pre>
  
  <p>Full Code:</p>
  
  <pre><code>Imports MySql.Data.MySqlClient
  Imports System.Net
  Imports System.IO
  
  Dim con As MySqlConnection = New MySqlConnection("Data Source=xxx.xxx.xxx.xxx;Database=productiontrackerpro;User ID=xxxxxxxx;Password=xxxxxxxx;")
  
  
  Public Sub LoadClients()
  
          Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM Lines WHERE Client = 'LEXAR')", con)
          Dim dt As DataTable = New DataTable()
  
          Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter(sql)
          DataAdapter1.Fill(dt)
  
  
          If dt.Rows.Count &gt; 0 Then
              ComboBox1.DataSource = dt
              ComboBox1.DisplayMember = "Line"
          End If
          con.Close()
  
  
  
  
      End Sub
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Lines WHERE Client = 'LEXAR')' at line 1
  </code></pre>