I have an ObjectDataSource that works fine unless I send it a string parameter greater than 10 charcters, when I obtain this error "12345678901ab is not a valid value for Int32"; is trying to insert a string parameter (UserID) in the integer Key. There are
two varchar(20) parameters and one Integer. One parameter is defined in the .aspx file and two are assigned on code behind
Well, yes, 12345678901ab is not a valid integer! I also don't see where you've defined the UserID parameter (and for that matter the ID_IMG parameter) (?). Also, the maximum value an Int32 can take is 2,147,483,647,
Of course '12345678901ab' is not a valid integer, this is the value that is assigned to UserID. As you can see in the code behind included, UserID and ID_IMG parameters are created and initialized in Page Init, and the Integer (IntRx) is assigned
a Session variable. '12345678901ab' is mistakenly trying to be assigned to IntRX, I don't know why and that is the problem. This only happens when UserID has more that 10 charaters, otherwise it works fine, no errors
This code means that your have a parameter called "KeyRX", and your Session's name is called "KeyOrigen", and its value must be convertable to Int32. And in the end it will be for KeyRX.
In the db table and the store procedure UserID and ID_IMG are Strings (varchar 15 and 20 respectively) and KeyRX an Integer. The Session("KeyOrigen") passes an evalued value from a text box. The "mistery" here is in the parameter ID_IMG, when it receives
a string with 10 or less characters it binds and retrieves the data correctly, but if it has 11 or more, it gives the error, as it is wrongfully assigning that string to the Integer KeyRx.
My stupid mistake ! I ckecked the store procedure several times and in all of them, I passed over the fact that it was casting the ID_IMG as an Ingeger, where it should be a String.
Thank you for your help, copying the code to paste it here was when I noticed the mistake.
drtrejos
Member
40 Points
84 Posts
ObjectDataSource confusing parameters
Nov 07, 2012 04:10 PM|LINK
I have an ObjectDataSource that works fine unless I send it a string parameter greater than 10 charcters, when I obtain this error "12345678901ab is not a valid value for Int32"; is trying to insert a string parameter (UserID) in the integer Key. There are two varchar(20) parameters and one Integer. One parameter is defined in the .aspx file and two are assigned on code behind
Any suggestions will be apprecited
This is the definition: (partial)
<asp:ObjectDataSource ID="ImageRxDsrc" runat="server" SelectMethod="GetImageRX" DeleteMethod="DeleteImageRx" TypeName="AdicionalesService"> <SelectParameters> <asp:SessionParameter Name="KeyRX" SessionField="KeyOrigen" Type="Int32" /> </SelectParameters> <DeleteParameters> <asp:Parameter Name="KeyImg" Type="Int32" /> </DeleteParameters> </asp:ObjectDataSource><div>This is in code behind:</div> <div>Uid = Dec.Decrypt(Request.Cookies("mipaciente")("Uid")).ToString SesID = Dec.Decrypt(Request.Cookies("SesID").Value) ImageRxDsrc.SelectParameters.Add("UserID", Data.DbType.String, Uid) ImageRxDsrc.SelectParameters.Add("ID_IMG", Data.DbType.String, SesID)
</div>MetalAsp.Net
All-Star
112032 Points
18231 Posts
Moderator
Re: ObjectDataSource confusing parameters
Nov 07, 2012 05:17 PM|LINK
Well, yes, 12345678901ab is not a valid integer! I also don't see where you've defined the UserID parameter (and for that matter the ID_IMG parameter) (?). Also, the maximum value an Int32 can take is 2,147,483,647,
Refer: http://msdn.microsoft.com/en-us/library/system.int32.maxvalue.aspx
drtrejos
Member
40 Points
84 Posts
Re: ObjectDataSource confusing parameters
Nov 07, 2012 08:26 PM|LINK
Of course '12345678901ab' is not a valid integer, this is the value that is assigned to UserID. As you can see in the code behind included, UserID and ID_IMG parameters are created and initialized in Page Init, and the Integer (IntRx) is assigned a Session variable. '12345678901ab' is mistakenly trying to be assigned to IntRX, I don't know why and that is the problem. This only happens when UserID has more that 10 charaters, otherwise it works fine, no errors
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: ObjectDataSource confusing parameters
Nov 08, 2012 04:18 AM|LINK
Hi,
Try to change the Type from "Int32" to "String" to insert the data with this value.
Hope this helps.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: ObjectDataSource confusing parameters
Nov 08, 2012 04:20 AM|LINK
Hi again,
This code means that your have a parameter called "KeyRX", and your Session's name is called "KeyOrigen", and its value must be convertable to Int32. And in the end it will be for KeyRX.
drtrejos
Member
40 Points
84 Posts
Re: ObjectDataSource confusing parameters
Nov 08, 2012 05:05 AM|LINK
In the db table and the store procedure UserID and ID_IMG are Strings (varchar 15 and 20 respectively) and KeyRX an Integer. The Session("KeyOrigen") passes an evalued value from a text box. The "mistery" here is in the parameter ID_IMG, when it receives a string with 10 or less characters it binds and retrieves the data correctly, but if it has 11 or more, it gives the error, as it is wrongfully assigning that string to the Integer KeyRx.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: ObjectDataSource confusing parameters
Nov 08, 2012 06:05 AM|LINK
Hi,
I think you can show us your full codes including your aspx codes as well as cs ones……
drtrejos
Member
40 Points
84 Posts
Re: ObjectDataSource confusing parameters
Nov 08, 2012 07:16 PM|LINK
My stupid mistake ! I ckecked the store procedure several times and in all of them, I passed over the fact that it was casting the ID_IMG as an Ingeger, where it should be a String.
Thank you for your help, copying the code to paste it here was when I noticed the mistake.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: ObjectDataSource confusing parameters
Nov 08, 2012 11:01 PM|LINK
Hi,
Nothing special, Can you tell us what mistake you've made and whether your problem is solved?