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.

这有什么问题?

4

1 回答 1

2

对我来说听起来像是一个本地化问题。我猜您正在以 dd/mm/yy 格式输入日期,但 ASP.NET 或 SQL Server 正在尝试使用不变的文化或 en-US 来解析它们,这需要 mm/dd/yy 格式。或者相反。将日期传递给 SQL Server 时,最好已经使用 解析它们,或者使用完全明确的格式DateTime.Parse将它们作为字符串传递。yyyy-MM-dd HH:mm:ss

于 2013-05-07T03:41:12.267 回答