ObjectDataSource DateTime Bug in .Net 2.0.

K

Keith Jackson

I have, over the last week, been attempting to play with the
ObjectDataSource binding an ASP.NET 2.0 UI through to a Data Access
Assembly.

Selection of data using the new GridView control worked flawlessly but, on
attempting any kind of data writing, the system produced the following
error...

"The DateModified field could not be converted from System.String to
System.DateTime"

I tried manually entering US format dates (I am UK based) - this worked. I
then tried setting up the Application culture settings for en-GB but no joy.

It seems that the ObjectDataSource is forcing use of the American date
format. There are three workarounds for this bug...

1) Set the application culture settings to en-US and use American date
format (i.e. Give up!).

2) Pass DateTime types to the DAL Object as strings and convert the exposed
property to an internal DateTime field.

3) Catch the Update by adding an event handler to the Page, as follows.

protected void GridView_RowUpdating(object sender, GridViewUpdateEventArgs
e)

{

e.NewValues[19] = Convert.ToDateTime(e.NewValues[19].ToString());

e.NewValues[20] = Convert.ToDateTime(e.NewValues[20].ToString());

}

Either of these solutions solve the above problem.
 

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,968
Messages
2,570,150
Members
46,696
Latest member
BarbraOLog

Latest Threads

Top