title: vb.net SQL causing - "Must declare the scalar variable "
body: <p>I've been stuck on this error for a while, in vb.net trying to connect to SQL and pull data from a table within a day, using parameters to do this, a datetimepicker - the data saved to SQL is in a custom datetime format <code>dd/MM/yyyy HH:mm:ss</code>,</p>
  
  <p>When i execute my code i get </p>
  
  <blockquote>
    <p>"Must declare the scalar variable "@line"</p>
  </blockquote>
  
  <p>When i remove the code " WHERE [line] = @line and date >= @startdata AND date &lt; @enddata " it works but shows all the data without the date range as it should.</p>
  
  <pre><code>connect()
  
  DataGridView1.AutoGenerateColumns = True
  
  cmd.Parameters.Clear()
  
  cmd.CommandText = @"SELECT board, defect, date, detail_x, detail_y, 
                            detail_width, detail_height 
                            FROM [sqlccmdefects] 
                            WHERE [line] = @line 
                               and date &gt;= @startdata 
                               AND date &lt; @enddata";
  
  cmd.Parameters.Add("@line", SqlDbType.VarChar, 30).Value = Form1.line.Text
  cmd.Parameters.Add("@startdata", SqlDbType.DateTime).Value = DateTimePicker1.Value
  cmd.Parameters.Add("@enddata", SqlDbType.DateTime).Value = DateTimePicker2.Value
  cmd.ExecuteScalar()
  
  Dim dataAdapter1 = New SqlDataAdapter(cmd.CommandText, con.ConnectionString)
  Dim table1 As New DataTable()
  table1.Locale = System.Globalization.CultureInfo.InvariantCulture
  dataAdapter1.Fill(table1)
  Me.BindingSource1.DataSource = table1
  
  DataGridView1.DataSource = BindingSource1
  
  disconnect()
  </code></pre>
  
  <p>All i get is a blank Datagridview with the scalar error.</p>