-1

This is what I have, but currently it does not work..

Help?

sqlGVQuarterly.SelectCommand = "SELECT [CleaningID], [WorkType], [QuarterSection],
[BasinID], [RecordDate], [TotalFootage], [H2O], [GritRemoved], [StartingStreet],
[LocationPurpose], [Operators], [JobHours], [LaborHours], [ChaseTruckHours],
[VacTruckHours], [JetTruckHours] FROM [SanSewerCleaning] 
WHERE [RecordDate] BETWEEN '1/1/ + ddlSelectYear.SelectedValue' AND '3/31/+ ddlSelectYear.SelectedValue'"
Agustin Meriles
  • 4,866
  • 3
  • 29
  • 44

5 Answers5

2

You're building your string incorrectly:

sqlGVQuarterly.SelectCommand = "SELECT [CleaningID], [WorkType], [QuarterSection],
[BasinID], [RecordDate], [TotalFootage], [H2O], [GritRemoved], [StartingStreet],
[LocationPurpose], [Operators], [JobHours], [LaborHours], [ChaseTruckHours],
[VacTruckHours], [JetTruckHours] FROM [SanSewerCleaning] 
WHERE [RecordDate] BETWEEN '1/1/"  + ddlSelectYear.SelectedValue +
"' AND '3/31/" + ddlSelectYear.SelectedValue + "'";
CAbbott
  • 8,078
  • 4
  • 31
  • 38
0

You are sending the string literal "ddlSelectYear.SelectedValue". Ensure you have a double quote after "1/1/" and before " AND".

Your code should look like:

sqlGVQuarterly.SelectCommand = "SELECT [CleaningID], [WorkType], [QuarterSection],
[BasinID], [RecordDate], [TotalFootage], [H2O], [GritRemoved], [StartingStreet],
[LocationPurpose], [Operators], [JobHours], [LaborHours], [ChaseTruckHours],
[VacTruckHours], [JetTruckHours] FROM [SanSewerCleaning] 
WHERE [RecordDate] BETWEEN '1/1/" + ddlSelectYear.SelectedValue+"' AND '3/31/"+ ddlSelectYear.SelectedValue+"'";
Royi Hagigi
  • 240
  • 1
  • 10
0

You are making the query string wrong. I suppose you want something like this:

sqlGVQuarterly.SelectCommand = "SELECT [CleaningID], [WorkType], [QuarterSection],
[BasinID], [RecordDate], [TotalFootage], [H2O], [GritRemoved], [StartingStreet],
[LocationPurpose], [Operators], [JobHours], [LaborHours], [ChaseTruckHours],
[VacTruckHours], [JetTruckHours] FROM [SanSewerCleaning] 
WHERE [RecordDate] BETWEEN '1/1/" + ddlSelectYear.SelectedValue + "' 
AND '3/31/" + ddlSelectYear.SelectedValue+"'";

Because the values ddlSelectYear.SelectedValue doesn't exist in the SQL Engine, it will throw you a syntax error

Agustin Meriles
  • 4,866
  • 3
  • 29
  • 44
0

I would use the yyyy-M-dd pattern as well instead so:

WHERE [RecordDate] BETWEEN '" + ddlSelectYear.SelectedValue + "-01-01' AND '" + ddlSelectYear.SelectedValue + "-03-31'"
keifer94
  • 136
  • 2
0

Also, if your time/date values default to midnight you will get:

Starting: 1/1/YYYY 00:00:00 Ending: 3/31/YYYY 00:00:00

Any records with timestamps that are on March 31st after midnight would not be included in your selected records.

Alan Penny
  • 182
  • 1
  • 5