Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

DateTime ddmmyyyy error when update recordset with BO

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
edaj6
Asked:
edaj6
  • 3
  • 2
1 Solution
 
Gustav BrockCIOCommented:
Try with:

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

Then pass variable date.

/gustav
0
 
edaj6Author Commented:
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
 
Gustav BrockCIOCommented:
Without knowing your code I guess it should be something like this:

BO.Date = DateTime.Parse(YourDateTextVariable);

or similar.

/gustav
0
 
edaj6Author Commented:
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
 
Gustav BrockCIOCommented:
Great.
But wouldn't this be fine as well:

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

/gustav
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now