Solved

DateTime ddmmyyyy error when update recordset with BO

Posted on 2011-09-19
5
333 Views
Last Modified: 2012-06-27
I have a gridview where ObjectDataSource is a list of BO.

One field in DB and BO is DateTime formatted ddmmyyyy.
The gridview shows all records fine, but when I try to update I get an error when the day is is after the 12th (eg 19-09-2011):
Cannot convert value of parameter 'Date' from 'System.String' to 'System.DateTime'

I guess the system expects a date time in us format, but I want to use ddmmyyyy format.
My web.config has
<globalization uiCulture="da" culture="da-DK" />


 
public class EBO
    {   public int EID { get; set; }
        public DateTime Date { get; set; }...

Open in new window

0
Comment
Question by:edaj6
  • 3
  • 2
5 Comments
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 36560152
Try with:

string dateText = "19-09-2011";
DateTime date = DateTime.Parse(dateText);

Then pass variable date.

/gustav
0
 

Author Comment

by:edaj6
ID: 36560244
The DataField "Date" is a bound field, in my gridview I want to update. Where  should you code be, in my BO?
The datatype of BO.Date is DateTime.

..Jakob
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 36560318
Without knowing your code I guess it should be something like this:

BO.Date = DateTime.Parse(YourDateTextVariable);

or similar.

/gustav
0
 

Author Comment

by:edaj6
ID: 36560544
Thanks it works,

Since I use a gridview for uodateing I had to add to gv_RowUpdating:

TextBox txtDate = (TextBox)row.FindControl("txtDate");
e.NewValues["Date"] = DateTime.Parse(txtDate.Text.ToString());

0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 36560764
Great.
But wouldn't this be fine as well:

e.NewValues["Date"] = DateTime.Parse(txtDate.Text);

/gustav
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now