Solved

DateTime ddmmyyyy error when update recordset with BO

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run time Error 4 34
Connection String 16 43
rest webservice call over https via c# 6 21
C#.NET and microsoft certification. 3 32
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

23 Experts available now in Live!

Get 1:1 Help Now