Showing posts with label view. Show all posts
Showing posts with label view. Show all posts

Saturday, March 31, 2012

String to date error

Hi guys Ive got a slight problem..

When i run my asp.net page through visual studio the application works fine, however when i puslish it and view it over myhttp://localhost page i get the following error "Conversion from string "28/8/2007" to type 'Date' is not valid." when selecting dates from a calendar control i created.

Im thinking this is some formatting issue having to do with EU/US Date format, however im not too sure about it and with a few research there are some help files stating to use globalization and once again im not sure how that works.

What im doing is assigning a date within an arraylist (which are of type dates) to a Date variable as below

Dim tempDate asDatetempDate = NewDate.Item(0) // arraylist of containing dates
Would appreciate some help regarding this issue

Thanks :)

It is a en-eu related problem. This article should help

http://msdn2.microsoft.com/en-us/library/2h3syy57.aspx
thanks that was interesting, also found out that the root to the problem was due to regional settings under the aspnet user account, my currently logged on account was set to UK however the user account aspnet was still on US therefore it kept showing dates in US format

Wednesday, March 28, 2012

string.format Problem

I am trying to fill in a summary in the footer of my grid view but I keep getting an error

Message="Format specifier was invalid."
make sure your method argumements are in the right format

lblsummary.Text = String.Format("Total hrs: {0:d}", hrtotalsTotal)

e.Row.Cells(2).Text = (hrtotalsTotal / 60).ToString(

"d")

I got this format from msdn what is causing this

Hi,

What is your hrtotalsTotal value?

From what I can see, you're trying to convert a double to DateTime presentation format... It does not make any sense. You should use TimeSpan object. And I think your hrtotalsTotal is actually a total number of minutes... anyways, try this:

Dim totalHoursAs Double = 3.4'3 hours 24 minutesDim tsAs TimeSpan = TimeSpan.FromHours(totalHours)Response.Write(ts.ToString())

hrtotalstotal is declared as a decimal and is the sum of a grid view col.

dim hrtotalstotal as decimal

I am just deviding hrstotalstotal/60 to get total hrs. in a decimal format ie 75 min = 1.15 hrs....

nothing to do with any dates or times.

e.Row.Cells(2).Text = (hrtotalsTotal / 60).ToString("d")


ok then.

My example should help you out on this.


Your format specifier is invalid becoz you have declared the variable as decimal and using the integer format specifier.

Try this

lblsummary.Text = String.Format("Total hrs: {0:f}", hrtotalsTotal)
e.Row.Cells(2).Text = (hrtotalsTotal / 60).ToString("f")

Thanks


where can I get a list of the format specifier

Check this linkhttp://blog.g9th.com/2007/01/29/string-formats-in-c.aspx

Thanks