Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DateTime ddmmyyyy error when update recordset with BO

Posted on 2011-09-19
5
340 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

838 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