Update control button

R

Rudy

Hello All!
Working on a data grid, with the edit button. Having problems with the
update button. I know my connection is being made, but I have tried so many
diffrent things, and I keep getting diffrent errors. I'm hoping sombody can
look at my code and tell what I'm doing wrong.

Public Sub grdProducts_UpdateCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
grdProducts.UpdateCommand

Dim Sqlconnection1 As New SqlConnection(SQL_CONNECTION_STRING)
Dim cmdProd As SqlCommand
Dim txtProductName As String = e.Item.Cells(1).Text
Dim txtSupplier As String = e.Item.Cells(2).Text
Dim txtCost As String = e.Item.Cells(4).Text
Dim txtSRP As String = e.Item.Cells(5).Text
Dim txtInStock As String = e.Item.Cells(3).Text
Dim strUpdate As String


Dim scmd As New SqlCommand(strUpdate, Sqlconnection1)

With scmd.Parameters


.Add(New SqlParameter("@ProductID", _
SqlDbType.Int)).Value = _
CInt(grdProducts.DataKeys(grdProducts.SelectedIndex).ToString
= txbProductID.Text)
grdProducts.EditItemIndex = 1


.Add(New SqlParameter("@ProductName", _
SqlDbType.NVarChar, 40)).Value = e.Item.Cells(2)

.Add(New SqlParameter("@SupplierPart", _
SqlDbType.NVarChar, 50)).Value = e.Item.Cells(3)

.Add(New SqlParameter("@UnitCost", _
SqlDbType.Money, 8)).Value = e.Item.Cells(4)

.Add(New SqlParameter("@UnitSRP", _
SqlDbType.Money, 8)).Value = e.Item.Cells(5)

.Add(New SqlParameter("@UnitsInStock", _
SqlDbType.Int)).Value = e.Item.Cells(6)

.Add(New SqlParameter("@Discontinued", _
SqlDbType.Bit)).Value = e.Item.Cells(5)

'' '.Add(New SqlParameter("@New", _
'' ' SqlDbType.Bit)).Value = chkNew.Checked
.Add(New SqlParameter("@Used", _
SqlDbType.Bit)).Value = e.Item.Cells(5)

End With
Sqlconnection1.Open()

scmd.ExecuteNonQuery()
BindProductsGrid()
Sqlconnection1.Close()
End Sub

Sorry if my code is a little messy, I been trying diffrent things, and
commenting alot of stuff. I took all the comments out.

The error i get now is "Index was out of range. Must be non-negative and
less than the size of the collection. Parameter name: index "

I know I'm pretty close, I'm just not sure where I'm going wrong.

TIA!!!

Rudy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top