ObjectDataSource DateTime isuue with en-gb culture


A

Anne Catterick

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.
 
Ad

Advertisements

B

Brock Allen

Perhaps this is your problem:

http://wintellect.com/WEBLOGS/wintellect/archive/2005/11/17/2363.aspx


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(IDictiona
ry
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.IPostBackEventHand
ler.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.
 
Ad

Advertisements

A

Anne Catterick

Alas no, this isn't my problem. As you will see HtmlEncode is set to false
and the formating string does work as expected, including working correctly
with the culture and displaying dd/mm/yyyy.

This issue is simply with, what appears to be, a data conversion bug when an
edited row is updated.

Anne.

Brock Allen said:
Perhaps this is your problem:

http://wintellect.com/WEBLOGS/wintellect/archive/2005/11/17/2363.aspx


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(IDictiona
ry
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.IPostBackEventHand
ler.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

Top