title: Insert Variable Into SQL Query Visual Studio 2010
body: <p>I have a SQL query that looks like this;</p>
  
  <pre><code>Dim query As String = "SELECT ID, " &amp; Environment.NewLine &amp; _
                        "month_of_sale, " &amp; Environment.NewLine &amp; _
                        "client_last_name, " &amp; Environment.NewLine &amp; _
                        "client_first_name, " &amp; Environment.NewLine &amp; _
                        "deal_number, " &amp; Environment.NewLine &amp; _
                        "stock_number, " &amp; Environment.NewLine &amp; _
                        "delivery_date, " &amp; Environment.NewLine &amp; _
                        "finance_manager, " &amp; Environment.NewLine &amp; _
                        "finance_income, " &amp; Environment.NewLine &amp; _
                        "record_entered " &amp; Environment.NewLine &amp; _
                        "FROM(dodge_records)" &amp; Environment.NewLine &amp; _
                        "WHERE month_of_sale = @month_of_sale AND client_last_name = @client_last_name" &amp; Environment.NewLine &amp; _
                        "ORDER BY client_last_name"
  </code></pre>
  
  <p>I am trying to insert a variable into the SQL query but I don't see it happening when I debug the website. Here is the rest of the code so that it makes more sense.</p>
  
  <pre><code>Case "Last Name"
                      Try
                          Dim query As String = "SELECT ID, " &amp; Environment.NewLine &amp; _
                              "month_of_sale, " &amp; Environment.NewLine &amp; _
                              "client_last_name, " &amp; Environment.NewLine &amp; _
                              "client_first_name, " &amp; Environment.NewLine &amp; _
                              "deal_number, " &amp; Environment.NewLine &amp; _
                              "stock_number, " &amp; Environment.NewLine &amp; _
                              "delivery_date, " &amp; Environment.NewLine &amp; _
                              "finance_manager, " &amp; Environment.NewLine &amp; _
                              "finance_income, " &amp; Environment.NewLine &amp; _
                              "record_entered " &amp; Environment.NewLine &amp; _
                              "FROM(dodge_records)" &amp; Environment.NewLine &amp; _
                              "WHERE month_of_sale = @month_of_sale" &amp; Environment.NewLine &amp; _
                              "WHERE client_last_name = @client_last_name" &amp; Environment.NewLine &amp; _
                              "ORDER BY client_last_name"
  
                          Using Connection = New MySqlConnection(connStr)
                              Using da = New MySqlDataAdapter(query, Connection)
                                  da.SelectCommand.Parameters.AddWithValue("@month_of_sale", CurrentMonth)
                                  da.SelectCommand.Parameters.AddWithValue("@client_last_name", ValueBoxText)
                                  Dim DS As New DataSet
                                  da.Fill(DS)
                                  DodgeSearchGridView.DataSource = DS
                                  DodgeSearchGridView.DataBind()
                                  Connection.Close()
                              End Using
                          End Using
                      Catch ex As Exception
                      End Try
  </code></pre>
  
  <p>CurrentMonth &amp; ValueBoxText are strings that I need inserted into the SQL query. Right now this isn't working how I want it to. I don't get an error message or anything, the query doesn't return anything and I have double checked the database to make sure there is data in it that would be returned by this query. Can anyone help me error check the code so I can find out how to make this work? Thanks!</p>