Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 16, 2012 12:47 PM by lionelsiu
Member
30 Points
38 Posts
Apr 15, 2012 06:42 PM|LINK
I have two textboxs which will store a date with format "dd-mm-yy", now I want to make these values to be the ControlParameter in a AccessDataSource.
But sometimes the system cannot recognize the date value (the system will treat the date format as "mm-dd-yy" instead of "dd-mm-yy".
How can I let the system to recognize the value of textbox to be a date with format "dd-mm-yy" ?
I know there is a method called DateTime.ParseExact() , can I parse the textbox values before putting them into the ControlParameter??
<asp:AccessDataSource ID="selectdate" runat="server" DataFile="database.mdb" SelectCommand="SELECT * from Table1 where Date1 >=? AND Date1 <=?"> <SelectParameters> <asp:ControlParameter ControlID="StartDate" Name="?" PropertyName="Value" DbType="DateTime" /> <asp:ControlParameter ControlID="EndDate" Name="?" PropertyName="Value" DbType="DateTime" /> </SelectParameters> </asp:AccessDataSource>
270 Points
75 Posts
Apr 15, 2012 07:10 PM|LINK
http://stackoverflow.com/questions/371987/validate-a-datetime-in-c-sharp
Apr 16, 2012 11:06 AM|LINK
Thanks for reply, but how can I parse the value in textbox when passing it to the ControlParameter in datasource?
Where should I put that code? Should it be in the OnSelecting event of AccessDataSource?
Could you please give me an example to do it?
Contributor
3230 Points
668 Posts
Apr 16, 2012 11:17 AM|LINK
Hi,
In code behind in AccessDataSource_selecting event you can format the date value as
{
DateTime result;
result = DateTime.ParseExact(e.Command.Parameters["?"].Value.ToString(),"d",CultureInfo.InvariantCulture);
e.Command.Parameters["?"].Value = result
}
Apr 16, 2012 12:47 PM|LINK
Thank you for your solution!
lionelsiu
Member
30 Points
38 Posts
Parse a DateTime to be a valid ControlParameter with DbType="DateTime"
Apr 15, 2012 06:42 PM|LINK
I have two textboxs which will store a date with format "dd-mm-yy", now I want to make these values to be the ControlParameter in a AccessDataSource.
But sometimes the system cannot recognize the date value (the system will treat the date format as "mm-dd-yy" instead of "dd-mm-yy".
How can I let the system to recognize the value of textbox to be a date with format "dd-mm-yy" ?
I know there is a method called DateTime.ParseExact() , can I parse the textbox values before putting them into the ControlParameter??
<asp:AccessDataSource ID="selectdate" runat="server" DataFile="database.mdb" SelectCommand="SELECT * from Table1 where Date1 >=? AND Date1 <=?"> <SelectParameters> <asp:ControlParameter ControlID="StartDate" Name="?" PropertyName="Value" DbType="DateTime" /> <asp:ControlParameter ControlID="EndDate" Name="?" PropertyName="Value" DbType="DateTime" /> </SelectParameters> </asp:AccessDataSource>hiza808
Member
270 Points
75 Posts
Re: Parse a DateTime to be a valid ControlParameter with DbType="DateTime"
Apr 15, 2012 07:10 PM|LINK
http://stackoverflow.com/questions/371987/validate-a-datetime-in-c-sharp
lionelsiu
Member
30 Points
38 Posts
Re: Parse a DateTime to be a valid ControlParameter with DbType="DateTime"
Apr 16, 2012 11:06 AM|LINK
Thanks for reply, but how can I parse the value in textbox when passing it to the ControlParameter in datasource?
Where should I put that code? Should it be in the OnSelecting event of AccessDataSource?
Could you please give me an example to do it?
tusharrs
Contributor
3230 Points
668 Posts
Re: Parse a DateTime to be a valid ControlParameter with DbType="DateTime"
Apr 16, 2012 11:17 AM|LINK
{result = DateTime.ParseExact(e.Command.Parameters["?"].Value.ToString(),"d",CultureInfo.InvariantCulture);e.Command.Parameters["?"].Value = result( Mark as Answer if it helps you out )
View my Blog
lionelsiu
Member
30 Points
38 Posts
Re: Parse a DateTime to be a valid ControlParameter with DbType="DateTime"
Apr 16, 2012 12:47 PM|LINK
Thank you for your solution!