Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Error!!!

Hi,
While updating a record i got another error.

"Server Error in '/UniplusWebClient' Application.
--------------------------------------------------------------------------------

Specified argument was out of the range of valid values. Parameter name: index
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.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index

Source Error:


Line 54:        Dim i As Integer
Line 55:        For i = 1 To UniplusDataSet.EmpTable.Columns.Count()
Line 56:            Dim t As TextBox = CType(e.Item.Cells(i).Controls(0), TextBox)
Line 57:            Dim row As DataRow = UniplusDataSet.EmpTable(e.Item.DataSetIndex)
Line 58:            row(UniplusDataSet.EmpTable.Columns(i - 1).Caption) = t.Text


Source File: c:\inetpub\wwwroot\UniplusWebClient\WebForm1.aspx.vb    Line: 56

Stack Trace:


[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index]
  System.Web.UI.ControlCollection.get_Item(Int32 index) +58
  UniplusWebClient.WebForm1.DataGrid1_UpdateCommand1(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\UniplusWebClient\WebForm1.aspx.vb:56
  System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +109
  System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +507
  System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
  System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +106
  System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
  System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121
  System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115
  System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
  System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138
  System.Web.UI.Page.ProcessRequestMain() +1292




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.2032; ASP.NET Version:1.1.4322.2032 "



The whole code for updatecommand is:

Private Sub DataGrid1_UpdateCommand1(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
        Dim i As Integer
        For i = 1 To UniplusDataSet.EmpTable.Columns.Count()
            Dim t As TextBox = CType(e.Item.Cells(i).Controls(0), TextBox)
            Dim row As DataRow = UniplusDataSet.EmpTable(e.Item.DataSetIndex)
            row(UniplusDataSet.EmpTable.Columns(i - 1).Caption) = t.Text
        Next
        If Me.UniplusDataSet.HasChanges() Then
            Dim ws As New UniplusWebClient.localhost.UniplusService
            ws.Credentials = System.Net.CredentialCache.DefaultCredentials
            Dim diffUniplus As New UniplusWebClient.localhost.UniplusDataSet
            diffUniplus.Merge(Me.UniplusDataSet.GetChanges())
            ws.uniplusUpdates(diffUniplus)
            UniplusDataSet.Merge(diffUniplus)
        End If
        DataGrid1.EditItemIndex = -1
        DataGrid1.DataBind()
    End Sub
End Class

Nitu singh
Thursday, October 28, 2004

I hope somebody would kindly help me out with this problem. I would appretiate it a lot.

Nitu singh
Thursday, October 28, 2004

I believe your problem is with line 56. The e.Item collection is zero-based, so when you say For i = 1 to Uniplus...Count, you are exceeding the indexes upper bound by one.

Try using For i = 0 to Uniplus...Count -1

Jefe'
Thursday, October 28, 2004

Which would also require you to change;
row(UniplusDataSet.EmpTable.Columns(i - 1).Caption) = t.Text
to;
row(UniplusDataSet.EmpTable.Columns(i).Caption) = t.Text

Jefe'
Thursday, October 28, 2004

I did the changes and now another error came up.
It says:
Exception Details: System.InvalidCastException: Specified cast is not valid. and its on the same line  56.

Nitu singh
Thursday, October 28, 2004

In C#, all arrays are 0-based. I would assume that VB.Net has the same syntax.  You'll get an InvalidCastException if you attempt to cast a null object into a typed object. This happens with DataTable.Rows[][] objects. You'll either have to return an empty string ("") in your SQL if there is a null value or make sure that you've got an object reference that is valid prior to attempting the cast.

Here's how I deal with it in my SQL:

select isnull(column1,"") value1, isnull(column2,"")..

Nick Ruisi
Tuesday, November 16, 2004

*  Recent Topics

*  Fog Creek Home