datetime error on insert to db

L

Lerp

Hi all,

What do I have to do in order to get my value from my textbox that is
formatted like 'mm/dd/yyyy' into a datetime database field ?

Currently getting an error: Syntax error converting datetime from character
string

I have 2 validators on this form field as seen below along with a sub that
is supposed to be called on ServerValidate (which it seems it is misfiring)

'DATE VALIDATOR SUB
Sub ValidateDate(Sender As Object, e As ServerValidateEventArgs)
e.IsValid = isDate(e.Value)
End Sub

<!--- FROM FORM --->
<tr valign="top">
<td align="left" class="bodycopy">Date Of Birth:</td>
<td align="left" class="bodycopy">
<asp:TextBox id="dateofbirth" CssClass="textbox" columns="10"
MaxLength="10" runat="server" />&nbsp;(mm/dd/yyyy format)
<asp:CustomValidator ControlToValidate="dateofbirth"
OnServerValidate="ValidateDate" ErrorMessage="Date is invalid! mm/dd/yyyy
format." Display="Dynamic" RunAt=server ID="Customvalidator1"/>
<asp:RequiredFieldValidator id="dobval" ControlToValidate="dateofbirth"
CssClass="bodyreq" Display="dynamic" Width="100%" ErrorMessage="Please enter
a date of birth." RUNAT="server"/>
</td>
</tr>





Cheers, Lerp :)
 
P

Peter Blum

Use the DateTime.ParseExcept() method. See the .net documenation for this
class and method.

Some suggestions:
1. The CompareValidator already handles validating dates. Set the Operator
property to DataTypeCheck and Type=Date. The format (mm/dd/yyyy) is
determined by the current thread which has a DateTimeFormatInfo object on
it. (Thread.CurrentCulture)

2. There are numerous third party DateTextBoxes available with popup
calendars and many other features. Some are free. You can find out about
these controls and the rich selection of other types of controls at the
Control Gallery of www.asp.net, www.123aspx.com and www.411asp.net. Mine is
"Peter's Date Package" (http://www.peterblum.com/datecontrols/home.aspx).

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,992
Messages
2,570,220
Members
46,805
Latest member
ClydeHeld1

Latest Threads

Top