Results 1 to 2 of 2

Thread: updating table with dataadapter

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Location
    Atlanta
    Posts
    24

    updating table with dataadapter

    I feel like this should be easy....

    I have a web form with a data adapter and a datagrid. I simply want to be able to use the data grid link buttons for edit, update, etc to modify my database table.

    I can edit the row on the web form, but the update code nevers seems to get run against the database (I am using SQL Profiler so I know the code never hits the DB). Shouldn't this happen when I call the update method of the sql data adapter ?!?

    I used the data adapter wizard to generate the update, delete commands (I know I could do this other ways but now I want to solve this problem). Here are my relevant event handlers:

    VB Code:
    1. Private Sub grdItems_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdItems.EditCommand
    2.         grdItems.EditItemIndex = e.Item.ItemIndex
    3.         grdItems.DataBind()
    4.     End Sub
    5.     Private Sub grdItems_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdItems.UpdateCommand
    6.         adpMatDwg.Update(dsItems, "UDTMaterialDrawing")
    7.         grdItems.EditItemIndex = -1
    8.         grdItems.DataBind()
    9.     End Sub

    Thanks in advance!

  2. #2
    Junior Member
    Join Date
    Jun 2002
    Location
    Midwest
    Posts
    27

    Re: updating table with dataadapter

    every time the page refreshes, the dataset is lost. you will have to refill the dataset, find the specific row based on a column in the datagrid that holds the unique ID, do your field assignments, update and rebind the dataset to the datagrid.

    dim txtName as TextBox
    txtName = e.item.cells(1).Controls(0)
    da.fill(ds, "tblTable")
    row = ds.tables("tblTable").rows.find(e.item.cells(0).text)

    row("Name") = txtName.Text

    da.Update(ds, "tblTable")
    ds.acceptchanges

    dgr.DataSource = ds
    dgr.DataBind()

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