CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    6

    Update Command in DataGrid

    Hey ,
    i am using datagrid and i want to update the data by updating the grid text box values now how can i asign the values from grid and update data in visual studio .net

  2. #2
    Join Date
    Mar 2004
    Posts
    6

    I have done it

    Please do the following things in the event of update command


    Dim txtCustomerId As TextBox = CType(e.Item.Cells(3).Controls(0), TextBox)
    Dim txtShipName As TextBox = CType(e.Item.Cells(5).Controls(0), TextBox)
    Dim txtShipCity As TextBox = CType(e.Item.Cells(6).Controls(0), TextBox)
    Dim txtShipRegion As TextBox = CType(e.Item.Cells(7).Controls(0), TextBox)
    Dim txtShipPostalCode As TextBox = CType(e.Item.Cells(8).Controls(0), TextBox)

    Dim CustomerId As String = txtCustomerId.Text
    Dim ShipName As String = txtShipName.Text
    Dim ShipCity As String = txtShipCity.Text
    Dim ShipRegion As String = txtShipRegion.Text
    Dim ShipPostalCode As String = txtShipPostalCode.Text

    Dim cmd As SqlCommand
    cmd = New SqlCommand("Update Orders set Shipname= '" & ShipName & "', ShipCity = '" & ShipCity & "' WHERE CustomerID = @CustomerId", conn)
    cmd.Parameters.Add(New SqlParameter("@CustomerId", SqlDbType.VarChar, 20))
    cmd.Parameters(0).Value = CustomerId
    cmd.ExecuteNonQuery()

    dgOrders.EditItemIndex = -1
    FilterOrders()
    Catch ex As SqlException
    Response.Write(ex.Message)

    End Try

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured