Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error Message
Message
 
 
To
03/05/2004 17:58:56
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00900533
Message ID:
00900534
Views:
11
Just a hint (as you asked for <g>). In .NET everything is 0-based. Could it be that you are using index as 1-based?

>This is the error message and my code. Can somebody give me a hint about why I am getting this error message? Thank you in advance.
>
>ERROR MSG:***************************************
>Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Exception Details: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
>
>CODE:***************************************
> Private Sub grdProducts_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdProducts.UpdateCommand
> Dim Ds As DataSet
> Dim myCommand As SqlCommand
> Dim UpdateCmd As String = "UPDATE showing SET cid = @cid, cmls = @cmls, nprice = @nprice, csubdivision = @csubdivision, caddress1 = @caddress1, caddress2 = @caddress2, ccity = @ccity, cstate = @cstate, czipcode = @czipcode, cbedrooms = @cbedrooms, cbathrooms = @cbathrooms, chalfbaths = @chalfbaths, cmstbed = @cmstbed, dexpdate = @dexpdate, cgarage = @cgarage, cyearbuilt = @cyearbuilt, clister = @clister, clockbox = @clockbox, cowner = @cowner, cvacant = @cvacant, chomephone = @chomephone, cbusphone = @cbusphone, cmobilphone = @cmobilphone, clesseesname = @clesseesname, cacsqft = @cacsqft, ctotalsqft = @ctotalsqft, cinstructions = @cinstructions, cotherinfo = @cotherinfo, cremarks = @cremarks, cdirections = @cdirections, cschooldistrict = @cschooldistrict WHERE cid = @cid"
> myCommand = New SqlCommand(UpdateCmd, MyConnection)
> myCommand.Parameters.Add(New SqlParameter("@cid", SqlDbType.VarChar, 10))
> myCommand.Parameters.Add(New SqlParameter("@cmls", SqlDbType.VarChar, 10))
> myCommand.Parameters.Add(New SqlParameter("@nprice", SqlDbType.Decimal, 18))
> myCommand.Parameters.Add(New SqlParameter("@csubdivision", SqlDbType.VarChar, 50))
> myCommand.Parameters.Add(New SqlParameter("@caddress1", SqlDbType.VarChar, 50))
> myCommand.Parameters.Add(New SqlParameter("@caddress2", SqlDbType.VarChar, 50))
> myCommand.Parameters.Add(New SqlParameter("@ccity", SqlDbType.VarChar, 40))
> myCommand.Parameters.Add(New SqlParameter("@cstate", SqlDbType.VarChar, 2))
> myCommand.Parameters.Add(New SqlParameter("@czipcode", SqlDbType.VarChar, 5))
> myCommand.Parameters.Add(New SqlParameter("@cbedrooms", SqlDbType.VarChar, 1))
> myCommand.Parameters.Add(New SqlParameter("@cbathrooms", SqlDbType.VarChar, 1))
> myCommand.Parameters.Add(New SqlParameter("@chalfbaths", SqlDbType.VarChar, 1))
> myCommand.Parameters.Add(New SqlParameter("@cmstbed", SqlDbType.VarChar, 1))
> myCommand.Parameters.Add(New SqlParameter("@dexpdate", SqlDbType.DateTime, 8))
> myCommand.Parameters.Add(New SqlParameter("@cgarage", SqlDbType.VarChar, 1))
> myCommand.Parameters.Add(New SqlParameter("@cyearbuilt", SqlDbType.VarChar, 4))
> myCommand.Parameters.Add(New SqlParameter("@clister", SqlDbType.VarChar, 50))
> myCommand.Parameters.Add(New SqlParameter("@clockbox", SqlDbType.VarChar, 10))
> myCommand.Parameters.Add(New SqlParameter("@cowner", SqlDbType.VarChar, 50))
> myCommand.Parameters.Add(New SqlParameter("@cvacant", SqlDbType.VarChar, 1))
> myCommand.Parameters.Add(New SqlParameter("@chomephone", SqlDbType.VarChar, 10))
> myCommand.Parameters.Add(New SqlParameter("@cbusphone", SqlDbType.VarChar, 10))
> myCommand.Parameters.Add(New SqlParameter("@cmobilphone", SqlDbType.VarChar, 10))
> myCommand.Parameters.Add(New SqlParameter("@clesseesname", SqlDbType.VarChar, 50))
> myCommand.Parameters.Add(New SqlParameter("@cacsqft", SqlDbType.VarChar, 10))
> myCommand.Parameters.Add(New SqlParameter("@ctotalsqft", SqlDbType.VarChar, 10))
> myCommand.Parameters.Add(New SqlParameter("@cinstructions", SqlDbType.VarChar, 200))
> myCommand.Parameters.Add(New SqlParameter("@cotherinfo", SqlDbType.VarChar, 100))
> myCommand.Parameters.Add(New SqlParameter("@cremarks", SqlDbType.VarChar, 100))
> myCommand.Parameters.Add(New SqlParameter("@cdirections", SqlDbType.VarChar, 100))
> myCommand.Parameters.Add(New SqlParameter("@cschooldistrict", SqlDbType.VarChar, 50))
>
> myCommand.Parameters("@cid").Value = Me.grdProducts.DataKeys(CInt(e.Item.ItemIndex))
>
> Dim Cols As String() = {"@cid", "@cmls", "@nprice", "@csubdivision", "@caddress1", "@caddress2", "@ccity", "@cstate", "@czipcode", "@cbedrooms", "@cbathrooms", "@chalfbaths", "@cmstbed", "@dexpdate", "@cgarage", "@cyearbuilt", "@clister", "@clockbox", "@cowner", "@cvacant", "@chomephone", "@cbusphone", "@cmobilphone", "@clesseesname", "@cacsqft", "@ctotalsqft", "@cinstructions", "@cotherinfo", "@cremarks", "@cdirections", "@cschooldistrict"}
> Dim NumCols As Integer = e.Item.Cells.Count
> Dim i As Integer
> For i = 4 To NumCols 'Skip first through fourth and last columns
> Dim CurrentTextBox As System.Web.UI.WebControls.TextBox
> CurrentTextBox = e.Item.Cells(i).Controls(0)
> Dim ColValue As String = CurrentTextBox.Text
> If i < 6 And ColValue = "" Then
> Me.lblError.Text = "ERROR!!!!!"
> End If
> myCommand.Parameters(Cols(i - 1)).Value = ColValue
> Next
> myCommand.Connection.Open()
> Try
> myCommand.ExecuteNonQuery()
> Me.grdProducts.EditItemIndex = -1
> Catch exp As SqlException
> Me.lblError.Text = "ERROR: Could not update record, please ensure the fields are correctly filled out"
> End Try
> myCommand.Connection.Close()
> Me.BindGrid()
> End Sub
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform