|
-
Jul 18th, 2005, 04:12 PM
#1
Thread Starter
Junior Member
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:
Private Sub grdItems_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdItems.EditCommand
grdItems.EditItemIndex = e.Item.ItemIndex
grdItems.DataBind()
End Sub
Private Sub grdItems_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdItems.UpdateCommand
adpMatDwg.Update(dsItems, "UDTMaterialDrawing")
grdItems.EditItemIndex = -1
grdItems.DataBind()
End Sub
Thanks in advance!
-
Jul 18th, 2005, 07:20 PM
#2
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|