title: Must declae 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 dd/MM/yyyy HH:mm:ss, </p>
  
  <p>When i execute my code i get "Must declare the scalar variable "@startdata". When i remove the code " and startdate >= @startdata  AND startdate &lt; @enddata " it works but shows all the data without the date range as it should.</p>
  
  <pre><code>connect()
      cmd.Parameters.Clear()
      cmd.CommandText = "SELECT status, startdate, seconds FROM [sqlccmlinestatus] WHERE line = '" &amp; ComboBox1.Text &amp; "' and startdate &gt;= @startdata  AND startdate &lt; @enddata "
      cmd.Parameters.AddWithValue("@startdata", DateTimePicker1.Value)
      cmd.Parameters.AddWithValue("@enddata", DateTimePicker1.Value.AddDays(1))
      cmd.ExecuteScalar()
      Dim dataAdapter = New SqlDataAdapter(cmd.CommandText, con.ConnectionString)
      Dim table As New DataTable()
  
      table.Locale = System.Globalization.CultureInfo.InvariantCulture
      dataAdapter.Fill(table)
      Me.BindingSource1.DataSource = table
  
      DataGridView1.DataSource = BindingSource1
  
      disconnect()
  
      DataGridView1.RowHeadersWidth = "28"
  
      DataGridView1.Columns(0).Width = 78
      DataGridView1.Columns(1).Width = 78
      DataGridView1.Columns(2).Width = 95
  
      DataGridView1.Columns(0).HeaderText = "Status:"
      DataGridView1.Columns(1).HeaderText = "Date:"
      DataGridView1.Columns(2).HeaderText = "Seconds:"
  
      DataGridView1.EnableHeadersVisualStyles = False
      DataGridView1.Rows(0).Selected = True
  </code></pre>
  
  <p>Any help would be great,</p>
  
  <p>Many Thanks,
  Pete</p>