469,619 Members | 1,869 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,619 developers. It's quick & easy.

Gridview + ObjectDatasource + UpdateMethod = Input string was not in a correct format

M C
Hi,
This is a problem that has been haunting me for days and I've come to a
complete dead-end. I'm using a objectdatasource to select and update a
gridview control. Populating with select works fine but updating gives
the "input string... " error. Any suggestions or links to a working
sample. Let me know if anyone needs any code posted...
Thanks in advance!
MC

Apr 17 '06 #1
7 4910
what kind of input string error?

"M C" <mi**************@gmail.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com...
Hi,
This is a problem that has been haunting me for days and I've come to a
complete dead-end. I'm using a objectdatasource to select and update a
gridview control. Populating with select works fine but updating gives
the "input string... " error. Any suggestions or links to a working
sample. Let me know if anyone needs any code posted...
Thanks in advance!
MC

Apr 18 '06 #2
Are you updating real or datetime values?

There's a bug in the ObjectDataSource that prevents it from working
properly if the current culture is "compatible" with the
InvariantCulture. For more info take a look here:

http://www.manuelabadia.com/blog/Per...5ceaf21cc.aspx

The only thing you can do to bypass this error if you're using the
ObjectDataSource is to set your current culture to the InvariantCulture
but probably this is not what you want to do as you'll loose your
datetime and real formats.

You can use my ExtendedObjectDataSource that is a component with more
functionality than the ObjectDataSource:

http://www.manuelabadia.com/products/EODS_features.aspx

You have to pay for the complete version but there's a free version
(look at the purchase page) that works like the ObjectDataSource and
doesn't have the "Input string was not in a correct format" error (but
doesn't have caching).

Hope it helps,
Manu.

Apr 18 '06 #3
MC
I'm only updating int and string values...
Here's a snippet of my code:

[ASPX page]:
<asp:GridView ID="gridViewNews" runat="server"
AutoGenerateColumns="False" DataSourceID="ObjectDataSource1"
DataKeyNames="cid,rid">
<Columns>
<asp:CommandField ShowEditButton="True" >
</asp:CommandField>
<asp:BoundField DataField="cid" HeaderText="CID" ReadOnly="True"
SortExpression="cid" />
<asp:BoundField DataField="rid" HeaderText="RID" ReadOnly="True"
SortExpression="rid" />
<asp:BoundField DataField="controlvocabulary"
HeaderText="Thesaurus" ReadOnly="False"
SortExpression="controlvocabulary" HtmlEncode="false" />
<asp:BoundField DataField="title" HeaderText="Rx Title"
ReadOnly="True" SortExpression="title" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
OldValuesParameterFormatString="original_{}"
SelectMethod="getInvalidItemByNews" UpdateMethod="editNews"
TypeName="Rx">
<UpdateParameters>
<asp:Parameter Name="original_cid" Type="Int32" />
<asp:Parameter Name="original_rid" Type="Int32" />
<asp:Parameter Name="controlvocabulary" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>

[CLASS page with UPDATE method]:
public static void editNews(int original_cid, int original_rid, string
controlvocabulary, string title) {
using (SqlConnection connection = new
SqlConnection(ConfigurationManager.ConnectionStrin gs["OFHC-RX_RxConnectionString"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("lex_EditNews",
connection)) {
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@contentid", SqlDbType.Int).Value =
original_cid;
command.Parameters.Add("@revisionid", SqlDbType.Int).Value
= original_rid;
command.Parameters.Add("@controledvocabvalue",
SqlDbType.NVarChar, 1000).Value = controlvocabulary;
int result = 0;
connection.Open();
result = command.ExecuteNonQuery();
connection.Close();
}
}
}

Apr 18 '06 #4
MC
Here's output error. I really have no clue to what or where this error
resides.
Thanks...

[FormatException: Input string was not in a correct format.]
System.Text.StringBuilder.FormatError() +54
System.Text.StringBuilder.AppendFormat(IFormatProv ider provider,
String format, Object[] args) +2834404
System.String.Format(IFormatProvider provider, String format,
Object[] args) +93

System.Web.UI.WebControls.ObjectDataSourceView.Mer geDictionaries(ParameterCollection
reference, IDictionary source, IDictionary destination, String
parameterNameFormatString) +229

System.Web.UI.WebControls.ObjectDataSourceView.Exe cuteUpdate(IDictionary
keys, IDictionary values, IDictionary oldValues) +2113
System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary
values, IDictionary oldValues, DataSourceViewOperationCallback
callback) +78
System.Web.UI.WebControls.GridView.HandleUpdate(Gr idViewRow row,
Int32 rowIndex, Boolean causesValidation) +1218
System.Web.UI.WebControls.GridView.HandleEvent(Eve ntArgs e, Boolean
causesValidation, String validationGroup) +853
System.Web.UI.WebControls.GridView.OnBubbleEvent(O bject source,
EventArgs e) +87
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEven t(Object source,
EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args) +35
System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
+86
System.Web.UI.WebControls.LinkButton.RaisePostBack Event(String
eventArgument) +153

System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler
sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
+172
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
+4900

Apr 18 '06 #5
I think you should change OldValuesParameterFormatString="original_{}"
to OldValuesParameterFormatString="original_{0}".

Hope it helps,
Manuel Abadia.

Apr 18 '06 #6
MC
and I tried the culture thing too - it didn't help. Is that something
thats applicable to my problem. As I said earlier, I'm not dealing
with real or datetime values.
MC

Apr 18 '06 #7
MC
THANK YOU!!!! I finally got some meaningful errors and in a split
second I got it fixed!

Apr 18 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Robert Smith jr. | last post: by
reply views Thread by avital | last post: by
reply views Thread by =?Utf-8?B?RGVubmlzIE1jQ2FydGh5?= | last post: by
5 posts views Thread by =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post: by
4 posts views Thread by tim.cavins | last post: by
reply views Thread by Jeff | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.