?
Solved

vb.net Date Problem

Posted on 2009-04-27
15
Medium Priority
?
601 Views
Last Modified: 2012-05-06
I have made an ASP application. I deployed it on the server. Application is working properly till the time i press a button which executes an INSERT SQL Statement. When i press this it gives the following message : "Sys.WebForms.PageRequestManagerServerErrorException:String was not recongnized as a valid Date Time."

While doing the insert i convert the text into data as follows:
Convert.ToDateTime(TextBox7.Text).ToString("MM/dd/yyyy")


This message dont appears on the pc where i developed this application. It appears only on the server.

regional setting for the machine where i developed this application and the server machine is "dd/MM/yyyy"

database is sql server 2005
What could be the reason behind this error?
0
Comment
Question by:salmanfazal
  • 6
  • 5
  • 4
15 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24239528
when you are inserting or updating the database with the date then before sending it to the database convert the date format to yyyy-MM-dd HH:mm:ss
convert it like this Convert.ToDateTime(TextBox7.Text).ToString("yyyy/MM/dd")
try again
0
 

Author Comment

by:salmanfazal
ID: 24239598
Its still the same. Working on the development machine but not on the deployment machine.
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24239601
Instead of "converting" a String to a Date, parse it using ParseExact, which accepts an input format....

    Date.ParseExact(TextBox7.Text, "dd/MM/yyyy", Nothing)

Wayne
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24239633
try this one
DateTime.Parse(TextBox7.Text, System.Globalization.CultureInfo.CreateSpecificCulture("en-US").DateTimeFormat).ToStirng()
0
 

Author Comment

by:salmanfazal
ID: 24239672
If apply the above syntax, it gives the following error message: "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."

I tried changing the format to MM/dd/yyyy, VB throws the following message:
"The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar."
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24239687
what is the value in the text box which you are trying to convert
because the error says that its not between the range of values expected
0
 

Author Comment

by:salmanfazal
ID: 24239694
i am not typing anything,i am picking up the values from the calendar. lets say "21/06/2009"
Another thing is why its happening only on the server machine .
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24239717
i really dont know why its happening on the server but i am assuming that the textbox7.text is empty
the value is not getting set in the textbox or its not coming back on the server side
0
 

Author Comment

by:salmanfazal
ID: 24239772
but its working fine on my machine and even on the server if i put the date with in 12 days then it will work. if i put after 12th date it will not work, so it shows that textbox is not empty
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24239819
then its definitely the way your calendar control is returning the values
if your regional setting is MM-dd-yyyy and your calender is returning the date in dd-MM-yyyy then the dates greater than 12 will not work because 13 and above are not valid months
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24240071
If you are using an ASP.Net Calendar control, why not simply use something like this?

    Calendar1.SelectedDate.ToString("MM/dd/yyyy")

BTW - to avoid any problems with date formats, I always use date format "dd-MMM-yy". Doing so avoids any confusion.

Wayne
0
 

Author Comment

by:salmanfazal
ID: 24240302
Referring to webtubbs comments : You mean to say i need to put this format (dd-MMM-yy) in the text box or the regional settings.?
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24240616
Neither. Use it in your SQL statement.
0
 
LVL 48

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24240644
And where does the Textbox come into it? Are you sending the date to the Textbox from the Calendar?
0
 

Accepted Solution

by:
salmanfazal earned 0 total points
ID: 24288756
well the problem solved by adding the following line in the web.config.
<globalization culture="en-NZ"/>

Thanks to all for assistance.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question