Update control button

Discussion in 'ASP .Net Web Controls' started by Rudy, Mar 4, 2005.

  1. Rudy

    Rudy Guest

    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
    Rudy, Mar 4, 2005
    #1
    1. Advertising

  2. Rudy

    MasterGaurav Guest

    MasterGaurav, Mar 5, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    1
    Views:
    506
    Kannan Meiappan
    Oct 27, 2004
  2. mesut
    Replies:
    0
    Views:
    661
    mesut
    Feb 19, 2007
  3. Henke

    Update without using Edit and Update button

    Henke, May 30, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    153
    Brock Allen
    Jun 1, 2006
  4. Jim Gilligan
    Replies:
    0
    Views:
    153
    Jim Gilligan
    Sep 1, 2005
  5. Sven Fischer
    Replies:
    0
    Views:
    465
    Sven Fischer
    Oct 22, 2012
Loading...

Share This Page