R
rn5a
The .NET 2.0 documentation states the following:
When using a DataSet or DataTable in conjunction with a DataAdapter & a
relational data source, use the Delete method of the DataRow to remove
the row. The Delete method marks the row as Deleted in the DataSet or
DataTable but does not remove it. Instead when the DataAdapter
encounters a row marked as Deleted, it executes its DeleteCommand
method to delete the row at the data source. The row can then be
permanently removed using the AcceptChanges method.
Now I have this code:
<script runat="server">
Sub Page_Load(.....)
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
Dim dSet As DataSet
Dim dTable As DataTable
sqlConn = New SqlConnection("..........")
sqlDapter = New SqlDataAdapter("SELECT * FROM Marks", sqlConn)
dSet = New DataSet()
sqlDapter.Fill(dSet, "Marks")
dTable = dSet.Tables("Marks")
'delete the 4th row from the DataTable
dTable.Rows(3).Delete()
dTable.Rows(3).AcceptChanges()
dgMarks.DataSource = dSet.Tables("Marks").DefaultView
dgMarks.DataBind()
End Sub
</script>
<form runat="server">
<asp
ataGrid ID="dgMarks" runat="server"/>
</form>
When I execute the above code, the 4th row gets deleted from the
DataTable & hence the DataGrid doesn't display that row. Now how do I
make the SqlDataAdapter encounter the 4th row which has been marked as
Deleted in the Page_Load sub? Do I have to add the OnDeleteCommand
event to the DataGrid like this?
<asp
ataGrid ID="dgMarks" OnDeleteCommand="DeleteItem"
runat="server"/>
& then add the event handler named "DeleteItem" which will have the
same code snippet that exists in the Page_Load sub (of course, except
for the 2 lines that immediately precede the 'End Sub' line)?
When using a DataSet or DataTable in conjunction with a DataAdapter & a
relational data source, use the Delete method of the DataRow to remove
the row. The Delete method marks the row as Deleted in the DataSet or
DataTable but does not remove it. Instead when the DataAdapter
encounters a row marked as Deleted, it executes its DeleteCommand
method to delete the row at the data source. The row can then be
permanently removed using the AcceptChanges method.
Now I have this code:
<script runat="server">
Sub Page_Load(.....)
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
Dim dSet As DataSet
Dim dTable As DataTable
sqlConn = New SqlConnection("..........")
sqlDapter = New SqlDataAdapter("SELECT * FROM Marks", sqlConn)
dSet = New DataSet()
sqlDapter.Fill(dSet, "Marks")
dTable = dSet.Tables("Marks")
'delete the 4th row from the DataTable
dTable.Rows(3).Delete()
dTable.Rows(3).AcceptChanges()
dgMarks.DataSource = dSet.Tables("Marks").DefaultView
dgMarks.DataBind()
End Sub
</script>
<form runat="server">
<asp
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
</form>
When I execute the above code, the 4th row gets deleted from the
DataTable & hence the DataGrid doesn't display that row. Now how do I
make the SqlDataAdapter encounter the 4th row which has been marked as
Deleted in the Page_Load sub? Do I have to add the OnDeleteCommand
event to the DataGrid like this?
<asp
![Big Grin :D :D](/styles/default/custom/smilies/grin.gif)
runat="server"/>
& then add the event handler named "DeleteItem" which will have the
same code snippet that exists in the Page_Load sub (of course, except
for the 2 lines that immediately precede the 'End Sub' line)?