Question: I have following sql which is show previous days records from table.

```
SELECT * FROM tblMeter WHERE
(Date >= DATEADD(day, DATEDIFF(day, 1, GETDATE()), 0))
AND
(Date < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0))

```

But how can I collect records with datetimepicker value in vb.net. 

Any help will be appreciated. 

Thanks

Answer: 
```
Dim command As New SqlCommand

command.CommandText = "SELECT * FROM tblMeter WHERE (Date >= @startDate) AND (Date <  @endDate)"
command.Parameters.AddWithValue("@startDate", startDateTimePicker.Value)
command.Parameters.AddWithValue("@endDate", endDateTimePicker.Value)

```

Then all you need to do is execute the command and use the results. If you need help with that, I can explain it further
There's various ways you can do it, I'd prefer to wrap that sql statement up in a stored procedure that had one input parameter called `@myDate` or something like that, then I'd use code similar to the one in [this sample](http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx) to retrieve the data and do what I need to do with it.

However, one thing I would change with that SQL statement is that I wouldn't do `SELECT *`, I'd change that to `SELECT [nameOfCol1], [nameOfCol2], etc` so that even if someone later adds more columns to that table that statement will still return the same data and there's no risk that my code will use the wrong columns.