g_shockTan
g_shockTan

Reputation: 355

ASP.net ObjectSource Parameter

I have an ObjectDataSource with a parameter from a query string. I'm getting the following error:

Value was either too large or too small for an Int32.

I believe the query string might be too long for it's datatype. The InfoSheetID is populated from the database. Is there another option I can take or modify the ObjectDataSource to prevent the error?

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
OldValuesParameterFormatString="original_{0}" 
        SelectMethod="GetInfoByInfoID" 
        TypeName="BLL.InfoViewBLL">
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="2148663911" Name="InfoSheetID" 
                QueryStringField="InfoSheetID" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>

Upvotes: 1

Views: 431

Answers (1)

Warlock
Warlock

Reputation: 7481

Int32.MaxValue is 2'147'483'647, that is lower than 2'148'663'911 which you use.

You can change type to Int64 or refactore your code to avoid using so big values.

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
OldValuesParameterFormatString="original_{0}" 
        SelectMethod="GetInfoByInfoID" 
        TypeName="BLL.InfoViewBLL">
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="2148663911" Name="InfoSheetID" 
                                                    ^^^^^^^^^^
                QueryStringField="InfoSheetID" Type="Int64" />
                                                     ^^^^^
        </SelectParameters>
    </asp:ObjectDataSource>

Upvotes: 2

Related Questions