Jump to content

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

- - - - -

  • Please log in to reply
4 replies to this topic

#1
avosoft

avosoft

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
Hello,
I get this error when try to do multiple delete from this code.(its not mine)


The error

Quote

Value was either too large or too small for an Int32.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.OverflowException: Value was either too large or too small for an Int32.

Source Error:

Line 18: If checkbox.Checked Then
Line 19: ' Retreive the ProductID
Line 20: Dim ProductID As Integer = Convert.ToInt16(GridView1.DataKeys(row.RowIndex).Value)
Line 21: ' Pass the value of the selected Employye ID to the Delete //command.
Line 22: SqlDataSource1.DeleteParameters("ProductID").DefaultValue = ProductID.ToString()

Can someone tell me hoe to solve this

thanks
Programming is all about good logic. Spend more time here

vHost for Apache:thumbup1:

#2
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
did you try debugging the code , what was the value that productID was holding.
also what value did the Gridview1.DataKeys[index].value hold.
as of now all i can do is point you to reliable sources, do have a look at the article below
http://connect.micro...flows-correctly


#3
avosoft

avosoft

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts
Hell,

Thanks for your response

i saved the product ID as big int in database. See the code am using for the grid below
<form runat="server" id="form1">

                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:msdsConnectionString1 %>"

                        SelectCommand="SELECT DISTINCT [cert_date], [manufacturer], [productid], [msds_date], [prod_name] FROM [files]"

                        DeleteCommand="DELETE  FROM [files] WHERE ProductID=@ProductID;"

            OnDeleted="On_Record_Deleted"

            >

            <DeleteParameters>

           <asp:Parameter Name="ProductID" />

       </DeleteParameters>

                    </asp:SqlDataSource>

                     

                    <asp:Label ID="Label1" runat="server" Font-Bold="True" Height="29px" Width="585px"></asp:Label>

                        <asp:GridView ID="GridView1" 

                        runat="server" 

                        AllowPaging="True" 

                        AutoGenerateColumns="False"

                        DataKeyNames="ProductID"

                        DataSourceID="SqlDataSource1" CellPadding="8" ForeColor="#333333" GridLines="None">

                            <Columns>

                                <asp:BoundField DataField="ProductID" HeaderText="ProductID" SortExpression="productid"  InsertVisible="False" ReadOnly="True" />

                                <asp:BoundField DataField="prod_name" HeaderText="ProductName" SortExpression="prod_name" />

                                <asp:BoundField DataField="manufacturer" HeaderText="Manufacturer" SortExpression="manufacturer" />

                                <asp:BoundField DataField="msds_date" HeaderText="Msds Date" SortExpression="msds_date" />

                                <asp:BoundField DataField="cert_date" HeaderText="Cert. Expire. Date" SortExpression="cert_date" />

                                <asp:TemplateField HeaderText="Check to Delete">   <ItemTemplate> <asp:CheckBox ID="cbRows" runat="server"/> </ItemTemplate>

 </asp:TemplateField>

                            </Columns>

                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

                            <EditRowStyle BackColor="#999999" />

                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

                            

                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />

                        </asp:GridView>

                        <asp:Button    ID="btnMultipleRowDelete"    OnClick="btnMultipleRowDelete_Click"    runat="server"    Text="Delete Selected DataRows" />

                        

                        </form>	

Programming is all about good logic. Spend more time here

vHost for Apache:thumbup1:

#4
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
please read what others post before replying ,
i want the values of Gridview1.datakeys[index].value & productID [in line dim productId as Integer ] when the exception occurs this is the Key to providing the solution.

#5
avosoft

avosoft

    Learning Programmer

  • Members
  • PipPipPip
  • 47 posts

gokuajmes said:

please read what others post before replying ,
i want the values of Gridview1.datakeys[index].value & productID [in line dim productId as Integer ] when the exception occurs this is the Key to providing the solution.

ok thanks i solved the problem, but instead i get another error

here

Exception Details: System.OverflowException: Value was either too large or too small for an Int32.


Source Error: 


Line 27:         (Trim$(txtProductName.Text) <> vbNullString) And (Trim$(txtManufacturer.Text) <> vbNullString) And _

Line 28:         (Msds_file.HasFile <> False) And (Cert_file.HasFile <> False) Then

Line 29:             Dim ProductID As Integer = Convert.ToInt32(Format(Now, "ddMMyyhms"))

Line 30:             Dim sMsds As String = "M" & ProductID

Line 31:             Dim sCert As String = "C" & ProductID



Source File: J:\RAC\MSDS\main\admin\upload.aspx    Line: 29

Programming is all about good logic. Spend more time here

vHost for Apache:thumbup1:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users