delete a row
I was hoping that someone could assist me in the following.
I have created a dataset in c# and have bound this to a datagrid and I want to delete a row in the datatable in the dataset.
I know how to add a row to the dataset but am unsure of how to delete a row. I want to delete a row by using the unique ID number but I am unsure of how to do this.
Can I use the indexof operator to obtain the index of the row in the datatable?
I am not using an adapter as the datasource is based on xml.
I would be grateful of any advice.
gopal krishnaPosted Jul 13, 2006, 6:23 AM
i deleted a row in dataset by using the following function..
i fill ds with xml file..
in that ds i wana delete particular row or record...
here this is the function...i hope this may use for u... if u have any dout's then mail me..
Sub DelXML(ByVal S As Object, ByVal E As DataGridCommandEventArgs) Dim strFolderName = Request.ServerVariables.Item("APPL_PHYSICAL_PATH") & "users\" & UserName Dim strFilePath As String
strFilePath = strFolderName & "\" & UserName & ".xml"
If E.CommandName = "Delete" Then If datagrid1.EditItemIndex = -1 Then Dim x1 As Stringx1 = datagrid1.DataKeys.Item(E.Item.ItemIndex)
Dim objdata As New DataSet Tryobjdata.ReadXml(strFilePath) 'xml file..
objdata.Tables("YourTablename").DefaultView.RowFilter = "TITLE='" & x1 & "'"
If objdata.Tables("YourTablename").DefaultView.Count > 0 Thenobjdata.Tables("YourTablename").DefaultView.Delete(0)
Else ' Label1.Text = "No Records Found..!" End Ifobjdata.Tables("YourTablename").DefaultView.RowFilter = ""
objdata.WriteXml(strFilePath)
CatchEnd Try
Else
End If End If End Sub