ObjectDataSource DateTime isuue with en-gb culture

G

Guest

Hi,

I have an british ASP.Net 2.0 application which is doing what (should) be
very simple. But I am having issues.

On my page I have a GridView as follows (some tags excluded for easy reading):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" DataKeyNames="Id"
OnRowUpdated="GridView1_RowUpdated">
<Columns>
<asp:BoundField DataField="CreateDate" HeaderText="Create Date"
SortExpression="CreateDate"
DataFormatString="{0:d}" ApplyFormatInEditMode="True"
ReadOnly="True" HtmlEncode="False">
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:CommandField ButtonType="Image"
CancelImageUrl="~/images/manager/false.gif"
EditImageUrl="~/images/manager/edit.gif"
ShowEditButton="True" UpdateImageUrl="~/images/manager/true.gif" />
</Columns>
</asp:GridView>

This is bound to an ObjectDataSource defined as follows:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetCampaigns"
TypeName="B3.Mailer.BusinessEntities.Campaign"
DataObjectTypeName="B3.Mailer.BusinessEntities.Campaign"
InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:SessionParameter Name="clientId" SessionField="ClientId"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

The update method is defined as:

public static void Update(Campaign campaign)
{
}

However, when I edit a row in the GridView and press the update button I get
the following error:

[InvalidOperationException: Cannot convert value of parameter 'CreateDate'
from 'System.String' to 'System.DateTime']
System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value,
Type type, String paramName) +485
System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object
value, Type destinationType, String paramName) +217
System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type
dataObjectType, IDictionary inputParameters) +548
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +1520
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values,
IDictionary oldValues, DataSourceViewOperationCallback callback) +179
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32
rowIndex, Boolean causesValidation) +1137
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +835
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs
e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +106
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument) +200

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

This appears to be caused by the date being in UK format (dd/mm/yyyy - which
is correct for this application) as dates which could also be in US format
(i.e. 12/12/2005) do not throw this error.

Both my browser and development machine are set to en-gb but there is no
Culture attribute set on the @Page tags on the page.

Is this a bug in the ObjectDataSource not conforming to globalization or am
I missing somthing?

Any help you can give will be much appreciated. Thanks in advance for your
help.

Regards,

Anne.
 
G

Guest

Hi Anne,

How do you define the "CreateDate" within the
"B3.Mailer.BusinessEntities.Campaign" class?
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Anne Catterick said:
Hi,

I have an british ASP.Net 2.0 application which is doing what (should) be
very simple. But I am having issues.

On my page I have a GridView as follows (some tags excluded for easy reading):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" DataKeyNames="Id"
OnRowUpdated="GridView1_RowUpdated">
<Columns>
<asp:BoundField DataField="CreateDate" HeaderText="Create Date"
SortExpression="CreateDate"
DataFormatString="{0:d}" ApplyFormatInEditMode="True"
ReadOnly="True" HtmlEncode="False">
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:CommandField ButtonType="Image"
CancelImageUrl="~/images/manager/false.gif"
EditImageUrl="~/images/manager/edit.gif"
ShowEditButton="True" UpdateImageUrl="~/images/manager/true.gif" />
</Columns>
</asp:GridView>

This is bound to an ObjectDataSource defined as follows:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetCampaigns"
TypeName="B3.Mailer.BusinessEntities.Campaign"
DataObjectTypeName="B3.Mailer.BusinessEntities.Campaign"
InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:SessionParameter Name="clientId" SessionField="ClientId"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

The update method is defined as:

public static void Update(Campaign campaign)
{
}

However, when I edit a row in the GridView and press the update button I get
the following error:

[InvalidOperationException: Cannot convert value of parameter 'CreateDate'
from 'System.String' to 'System.DateTime']
System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value,
Type type, String paramName) +485
System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object
value, Type destinationType, String paramName) +217
System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type
dataObjectType, IDictionary inputParameters) +548
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +1520
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values,
IDictionary oldValues, DataSourceViewOperationCallback callback) +179
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32
rowIndex, Boolean causesValidation) +1137
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +835
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs
e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +106
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument) +200

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

This appears to be caused by the date being in UK format (dd/mm/yyyy - which
is correct for this application) as dates which could also be in US format
(i.e. 12/12/2005) do not throw this error.

Both my browser and development machine are set to en-gb but there is no
Culture attribute set on the @Page tags on the page.

Is this a bug in the ObjectDataSource not conforming to globalization or am
I missing somthing?

Any help you can give will be much appreciated. Thanks in advance for your
help.

Regards,

Anne.
 
G

Guest

Hi,

It's a simple private field with public accessors:

private DateTime _CreateDate;

public DateTime CreateDate
{
get { return _CreateDate; }
set { _CreateDate = value; }
}

Any ideas?

Thanks,

Anne.
Phillip Williams said:
Hi Anne,

How do you define the "CreateDate" within the
"B3.Mailer.BusinessEntities.Campaign" class?
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Anne Catterick said:
Hi,

I have an british ASP.Net 2.0 application which is doing what (should) be
very simple. But I am having issues.

On my page I have a GridView as follows (some tags excluded for easy reading):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" DataKeyNames="Id"
OnRowUpdated="GridView1_RowUpdated">
<Columns>
<asp:BoundField DataField="CreateDate" HeaderText="Create Date"
SortExpression="CreateDate"
DataFormatString="{0:d}" ApplyFormatInEditMode="True"
ReadOnly="True" HtmlEncode="False">
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:CommandField ButtonType="Image"
CancelImageUrl="~/images/manager/false.gif"
EditImageUrl="~/images/manager/edit.gif"
ShowEditButton="True" UpdateImageUrl="~/images/manager/true.gif" />
</Columns>
</asp:GridView>

This is bound to an ObjectDataSource defined as follows:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetCampaigns"
TypeName="B3.Mailer.BusinessEntities.Campaign"
DataObjectTypeName="B3.Mailer.BusinessEntities.Campaign"
InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:SessionParameter Name="clientId" SessionField="ClientId"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

The update method is defined as:

public static void Update(Campaign campaign)
{
}

However, when I edit a row in the GridView and press the update button I get
the following error:

[InvalidOperationException: Cannot convert value of parameter 'CreateDate'
from 'System.String' to 'System.DateTime']
System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value,
Type type, String paramName) +485
System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object
value, Type destinationType, String paramName) +217
System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type
dataObjectType, IDictionary inputParameters) +548
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +1520
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values,
IDictionary oldValues, DataSourceViewOperationCallback callback) +179
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32
rowIndex, Boolean causesValidation) +1137
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +835
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs
e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +106
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument) +200

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

This appears to be caused by the date being in UK format (dd/mm/yyyy - which
is correct for this application) as dates which could also be in US format
(i.e. 12/12/2005) do not throw this error.

Both my browser and development machine are set to en-gb but there is no
Culture attribute set on the @Page tags on the page.

Is this a bug in the ObjectDataSource not conforming to globalization or am
I missing somthing?

Any help you can give will be much appreciated. Thanks in advance for your
help.

Regards,

Anne.
 
G

Guest

Hi Anne,

If I build a web page that allows the user’s browser to determine the
display of the date, yet my database operates on a server using the culture
setting for en-us, then I would get the error that you got as in this demo:
http://www.webswapp.com/CodeSamples/aspnet20/GridView_2c_error.aspx

If I add an UpdateParameters section within my objectDataSource defintion to
explicitly cast the edited values to their appropriate date type, I do not
get that error as in this demo:
http://www.webswapp.com/CodeSamples/aspnet20/GridView_2c.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Anne Catterick said:
Hi,

It's a simple private field with public accessors:

private DateTime _CreateDate;

public DateTime CreateDate
{
get { return _CreateDate; }
set { _CreateDate = value; }
}

Any ideas?

Thanks,

Anne.
Phillip Williams said:
Hi Anne,

How do you define the "CreateDate" within the
"B3.Mailer.BusinessEntities.Campaign" class?
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Anne Catterick said:
Hi,

I have an british ASP.Net 2.0 application which is doing what (should) be
very simple. But I am having issues.

On my page I have a GridView as follows (some tags excluded for easy reading):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" DataKeyNames="Id"
OnRowUpdated="GridView1_RowUpdated">
<Columns>
<asp:BoundField DataField="CreateDate" HeaderText="Create Date"
SortExpression="CreateDate"
DataFormatString="{0:d}" ApplyFormatInEditMode="True"
ReadOnly="True" HtmlEncode="False">
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:CommandField ButtonType="Image"
CancelImageUrl="~/images/manager/false.gif"
EditImageUrl="~/images/manager/edit.gif"
ShowEditButton="True" UpdateImageUrl="~/images/manager/true.gif" />
</Columns>
</asp:GridView>

This is bound to an ObjectDataSource defined as follows:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetCampaigns"
TypeName="B3.Mailer.BusinessEntities.Campaign"
DataObjectTypeName="B3.Mailer.BusinessEntities.Campaign"
InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:SessionParameter Name="clientId" SessionField="ClientId"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

The update method is defined as:

public static void Update(Campaign campaign)
{
}

However, when I edit a row in the GridView and press the update button I get
the following error:

[InvalidOperationException: Cannot convert value of parameter 'CreateDate'
from 'System.String' to 'System.DateTime']
System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value,
Type type, String paramName) +485
System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object
value, Type destinationType, String paramName) +217
System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type
dataObjectType, IDictionary inputParameters) +548
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +1520
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values,
IDictionary oldValues, DataSourceViewOperationCallback callback) +179
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32
rowIndex, Boolean causesValidation) +1137
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +835
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs
e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +106
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument) +200

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

This appears to be caused by the date being in UK format (dd/mm/yyyy - which
is correct for this application) as dates which could also be in US format
(i.e. 12/12/2005) do not throw this error.

Both my browser and development machine are set to en-gb but there is no
Culture attribute set on the @Page tags on the page.

Is this a bug in the ObjectDataSource not conforming to globalization or am
I missing somthing?

Any help you can give will be much appreciated. Thanks in advance for your
help.

Regards,

Anne.
 
G

Guest

Hi Philip,

Your a geneous! Thanks, that works great!

I wish the MSDN documentation actually mentioned this!

Thanks again,

Anne.

Phillip Williams said:
Hi Anne,

If I build a web page that allows the user’s browser to determine the
display of the date, yet my database operates on a server using the culture
setting for en-us, then I would get the error that you got as in this demo:
http://www.webswapp.com/CodeSamples/aspnet20/GridView_2c_error.aspx

If I add an UpdateParameters section within my objectDataSource defintion to
explicitly cast the edited values to their appropriate date type, I do not
get that error as in this demo:
http://www.webswapp.com/CodeSamples/aspnet20/GridView_2c.aspx

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Anne Catterick said:
Hi,

It's a simple private field with public accessors:

private DateTime _CreateDate;

public DateTime CreateDate
{
get { return _CreateDate; }
set { _CreateDate = value; }
}

Any ideas?

Thanks,

Anne.
Phillip Williams said:
Hi Anne,

How do you define the "CreateDate" within the
"B3.Mailer.BusinessEntities.Campaign" class?
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


:

Hi,

I have an british ASP.Net 2.0 application which is doing what (should) be
very simple. But I am having issues.

On my page I have a GridView as follows (some tags excluded for easy reading):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" DataKeyNames="Id"
OnRowUpdated="GridView1_RowUpdated">
<Columns>
<asp:BoundField DataField="CreateDate" HeaderText="Create Date"
SortExpression="CreateDate"
DataFormatString="{0:d}" ApplyFormatInEditMode="True"
ReadOnly="True" HtmlEncode="False">
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:CommandField ButtonType="Image"
CancelImageUrl="~/images/manager/false.gif"
EditImageUrl="~/images/manager/edit.gif"
ShowEditButton="True" UpdateImageUrl="~/images/manager/true.gif" />
</Columns>
</asp:GridView>

This is bound to an ObjectDataSource defined as follows:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetCampaigns"
TypeName="B3.Mailer.BusinessEntities.Campaign"
DataObjectTypeName="B3.Mailer.BusinessEntities.Campaign"
InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:SessionParameter Name="clientId" SessionField="ClientId"
Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>

The update method is defined as:

public static void Update(Campaign campaign)
{
}

However, when I edit a row in the GridView and press the update button I get
the following error:

[InvalidOperationException: Cannot convert value of parameter 'CreateDate'
from 'System.String' to 'System.DateTime']
System.Web.UI.WebControls.ObjectDataSourceView.ConvertType(Object value,
Type type, String paramName) +485
System.Web.UI.WebControls.ObjectDataSourceView.BuildObjectValue(Object
value, Type destinationType, String paramName) +217
System.Web.UI.WebControls.ObjectDataSourceView.BuildDataObject(Type
dataObjectType, IDictionary inputParameters) +548
System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +1520
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values,
IDictionary oldValues, DataSourceViewOperationCallback callback) +179
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32
rowIndex, Boolean causesValidation) +1137
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean
causesValidation, String validationGroup) +835
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs
e) +162
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source,
EventArgs e) +118
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
System.Web.UI.WebControls.ImageButton.OnCommand(CommandEventArgs e) +106
System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String
eventArgument) +200

System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +32
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +72
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3840

This appears to be caused by the date being in UK format (dd/mm/yyyy - which
is correct for this application) as dates which could also be in US format
(i.e. 12/12/2005) do not throw this error.

Both my browser and development machine are set to en-gb but there is no
Culture attribute set on the @Page tags on the page.

Is this a bug in the ObjectDataSource not conforming to globalization or am
I missing somthing?

Any help you can give will be much appreciated. Thanks in advance for your
help.

Regards,

Anne.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top