Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error Message
Message
From
03/05/2004 17:58:56
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Error Message
Miscellaneous
Thread ID:
00900533
Message ID:
00900533
Views:
49
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
Next
Reply
Map
View

Click here to load this message in the networking platform