1
我有這個gridview的,我用的SqlDataSource錯誤:當我選擇日期時轉換日期和/或時間從字符串轉換失敗?
這是我的選擇命令,
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TAXIConnectionString %>"
SelectCommand="SELECT [TripId] FROM [BookingMaster]
WHERE(([PickupLocation] = @PickupLocation or @PickupLocation is null)
AND ([DestinationLocation] = @DestinationLocation
or @DestinationLocation is null)
AND ([Status] = @Status or @Status is null)
AND (cast([PickupDateTime] as date) = @PickupDateTime
or @PickupDateTime is null))"
CancelSelectOnNullParameter="False">
<SelectParameters>
<asp:ControlParameter ControlID="ddPickup" Name="PickupLocation"
PropertyName="SelectedValue" Type="String"
ConvertEmptyStringToNull="true" />
<asp:ControlParameter ControlID="ddDestination" Name="DestinationLocation"
PropertyName="SelectedValue" Type="String"
ConvertEmptyStringToNull="true" />
<asp:ControlParameter ControlID="ddStatus" Name="Status"
PropertyName="SelectedValue" Type="String"
ConvertEmptyStringToNull="true" />
<asp:ControlParameter ControlID="txtBookingDate" Name="PickupDateTime"
PropertyName="Text" Type="String" ConvertEmptyStringToNull="true" />
</SelectParameters>
</asp:SqlDataSource>
,但正如我13或者之後選擇日期錯誤來了......
Server Error in '/' Application.
Conversion failed when converting date and/or time from character string.
這有什麼不對?
另外,你的數據庫列'[PickupDateTime]'實際上是一個日期時間列嗎?如果沒有,是不是有原因?如果是這樣,你不需要將它施放到日期。 – Adrian 2013-05-07 03:43:11
我用「[PickupDateTime]」作爲varchar,bcoz它的存儲日期時間到數據庫,但我只需要比較日期而不是時間這就是你選擇投用於比較日期.. – Saranya 2013-05-07 03:45:38
在這種情況下,你應該使用'日期'數據類型。將日期存儲爲字符串對於數據質量和性能來說是一個壞主意。 – mroach 2013-05-07 03:59:03