-1

这是我所拥有的,但目前它不起作用..

帮助?

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'"
4

5 回答 5

2

您正在错误地构建字符串:

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 + "'";
于 2013-01-04T21:31:24.857 回答
0

此外,如果您的时间/日期值默认为午夜,您将获得:

开始:1/1/YYYY 00:00:00 结束:3/31/YYYY 00:00:00

任何时间戳为 3 月 31 日午夜之后的记录都不会包含在您选择的记录中。

于 2013-01-04T21:34:30.410 回答
0

您正在发送字符串文字“ddlSelectYear.SelectedValue”。确保在“1/1/”之后和“AND”之前有双引号。

您的代码应如下所示:

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+"'";
于 2013-01-04T21:31:26.260 回答
0

您使查询字符串错误。我想你想要这样的东西:

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+"'";

因为值 ddlSelectYear.SelectedValue 在 SQL 引擎中不存在,它会抛出一个语法错误

于 2013-01-04T21:31:53.187 回答
0

我也会使用 yyyy-M-dd 模式,而不是这样:

WHERE [RecordDate] BETWEEN '" + ddlSelectYear.SelectedValue + "-01-01' AND '" + ddlSelectYear.SelectedValue + "-03-31'"
于 2013-01-04T21:34:18.280 回答