0

こんにちは、SQL Server に datetime データ型の日付を保存したいと考えています。検索画面で、パラメーターを日付のみとして指定しています。

では、どうすればクエリとして設定できますか? 私のコードは次のとおりです。

<asp:SqlDataSource 
     ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:TAXIConnectionString %>" 
     SelectCommand="SELECT [TripId] FROM [BookingMaster] 
              WHERE ( ([PickupDateTime] = @PickupDateTime or @PickupDateTime is null))" 
     CancelSelectOnNullParameter="False">
     <SelectParameters>
         <asp:ControlParameter ControlID="txtBookingDate" 
              Name="PickupDateTime" PropertyName="Text" Type="String" 
              ConvertEmptyStringToNull="true" />
     </SelectParameters>
</asp:SqlDataSource>     
4

1 に答える 1

3

Sql2008 以降を使用している場合は、DATE 型を使用できます。選択コマンドは次のようになります。

SelectCommand="SELECT [TripId] FROM [BookingMaster] 
              WHERE ( (cast([PickupDateTime] as date) = @PickupDateTime or @PickupDateTime is null))"
于 2013-05-06T17:29:51.163 に答える