Date entered from textbox becomes null (1/1/1900) when entered into SQL table.

T

TN Bella

Hello,

I was looking through the older posts for a solution to this problem,
but I am still confused on how to fix my problem. There are two dates on
my form, one (txtInvDate) is entered by the user and has a validator
(reDate) attached for specific dates that can be entered. The second
date (txtRptDate) is another textbox that is filled with current date,
that can not be changed by the user. The date (txtRptDate) that cannot
be changed by the user inputs fine into my SQL table, however the other
date (txtInvDate) does not, instead I get a null value 1/1/1900. How can
I fix the txtInvDate to work like the other inserted date?

This is something that I have tried:

Dim MySQL as string = "Insert into a_p.dbo.tbl_ap_web_ce_inv_terms
(splr_cd, rpt_date, inv_numb, inv_dat) Values ('" & txtSupCD.text &
"','" & txtRptDate.text & "','" & txtInvNum.text & "'," &
CType(txtInvDate.text,Date).ToShortDateString & ")"

Both dates are set for datetime 8 in the SQL table, inv_dat (txtInvDate)
is one of the three primary keys (I took the primary key off of inv_dat
and it still didn't work correctly) .

and my first attempt:
& txtInvDate.text & ")"

'reDate is the validator for txtInvDate
'Validation for Invoice Date, dates < 3 years OR > 30 days are
not accepted
reDate.MinimumValue =
CDate(DateTime.Now.AddYears(-3).ToShortDateString)
reDate.MaximumValue =
CDate(DateTime.Now.AddDays(30).ToShortDateString)

'Current date input for Receipt Date textbox, it can't not be
changed by user.
txtRptDate.Text = DateTime.Now.ToShortDateString()

'Here are my textboxes:
<asp:textbox id="txtInvDate" runat="server"
Width="97px"></asp:textbox>
<asp:RangeValidator id="reDate"
runat="server" ErrorMessage="Invoice Date"
ControlToValidate="txtInvDate" EnableClientScript="true"
type="Date">Please make sure the date is not older than 3 years or
greater than 30 days.</asp:RangeValidator>

<asp:TextBox id="txtRptDate" runat="server"
Width="96px" Enabled="False"></asp:TextBox>

Thanks in advance for any assistance to this problem, it has been
driving me nuts!! Thank you!
Oh, one more thing..>I am using Web Matrix 1.0 net framework in VB and
not C#.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
T

TN Bella

Thanks for looking at my problem but it is now fixed.

...I was missing the single quotes in my insert sql statement:

"','" & CType(txtInvDate.text,Date).ToShortDateString & "')"

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 

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

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top