salmanfazal
asked on
vb.net Date Problem
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.PageRequestM anagerServ erErrorExc eption:Str ing was not recongnized as a valid Date Time."
While doing the insert i convert the text into data as follows:
Convert.ToDateTime(TextBox 7.Text).To String("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?
While doing the insert i convert the text into data as follows:
Convert.ToDateTime(TextBox
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?
ASKER
Its still the same. Working on the development machine but not on the deployment machine.
Instead of "converting" a String to a Date, parse it using ParseExact, which accepts an input format....
Date.ParseExact(TextBox7.T ext, "dd/MM/yyyy", Nothing)
Wayne
Date.ParseExact(TextBox7.T
Wayne
try this one
DateTime.Parse(TextBox7.Te xt, System.Globalization.Cultu reInfo.Cre ateSpecifi cCulture(" en-US").Da teTimeForm at).ToStir ng()
DateTime.Parse(TextBox7.Te
ASKER
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.Grego rianCalend ar."
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.Grego
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
because the error says that its not between the range of values expected
ASKER
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 .
Another thing is why its happening only on the server machine .
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
the value is not getting set in the textbox or its not coming back on the server side
ASKER
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
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
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
If you are using an ASP.Net Calendar control, why not simply use something like this?
Calendar1.SelectedDate.ToS tring("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
Calendar1.SelectedDate.ToS
BTW - to avoid any problems with date formats, I always use date format "dd-MMM-yy". Doing so avoids any confusion.
Wayne
ASKER
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.?
Neither. Use it in your SQL statement.
And where does the Textbox come into it? Are you sending the date to the Textbox from the Calendar?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
convert it like this Convert.ToDateTime(TextBox
try again