Groups | Blog | Home
all groups > visual studio .net general > november 2006 >

visual studio .net general : DateTime and Object Data Source


Pdub
11/13/2006 1:26:03 PM
I have a page with 4 text boxes: Start Date, Start Time, End Date, End Time.
My database has a table with 2 fields: StartDate_Time, EndDate_Time. I'm
trying to set the value of my select parameters to a combination of date and
time. I thought I was on the right path with this code:
ObjectDataSource1.SelectParameters("StartDate").DefaultValue =
dStartDateTime.ToUniversalTime

However, when I check the date values in the method, the date is being sent
without the time. Where am I going wrong?

Object Data Source:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
OldValuesParameterFormatString="original_{0}"
SelectMethod="GetAvailableRooms" TypeName="RoomsAvailable">
<SelectParameters>
<asp:ControlParameter ControlID="txtEndDate" Name="EndDate"
PropertyName="Text" Type="DateTime" />
<asp:ControlParameter ControlID="txtStartDate" Name="StartDate"
PropertyName="Text" Type="DateTime" />
</SelectParameters>
</asp:ObjectDataSource>


Method From Business Logic Layer
<System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, True)> _
Public Function GetAvailableRooms(ByVal EndDate As Nullable(Of DateTime),
ByVal StartDate As Nullable(Of DateTime)) As
RoomsDataSet.RoomsAvailableDataTable
Return Adapter.GetAvailableRooms(EndDate, StartDate)
End Function

Button click event:
Dim sStartDateTime As String = txtStartDate.Text & " " & txtStartTime.Text
Dim sEndDateTime As String = txtEndDate.Text & " " & txtEndTime.Text
Dim dStartDateTime As DateTime = DateTime.Parse(sStartDateTime)
Dim dEndDateTime As DateTime = DateTime.Parse(sEndDateTime)
ObjectDataSource1.SelectParameters("StartDate").DefaultValue =
dStartDateTime.ToUniversalTime
ObjectDataSource1.SelectParameters("EndDate").DefaultValue =
Pdub
11/15/2006 5:26:02 AM
I figured this one out. In my object data source I had the date parameter set
to my text box. I thought the following would over ride that setting:

ObjectDataSource1.SelectParameters("StartDate").DefaultValue =
dStartDateTime.ToUniversalTime

I set the parameter source to none and then everything worked.

[quoted text, click to view]
AddThis Social Bookmark Button