I wish to remove a datarow, how do I do that? In my code below I've added a new row, but if try to use the command .RemoveRow() an error occurs.
Code:<%@ Page Language="vb" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.OleDb" %> <script runat="server"> Sub Page_Load(Sender As Object, E As EventArgs) Dim objDataSet As New DataSet() ' read in the XML file objDataSet.ReadXml(Server.MapPath("WroxBooks.xml")) ' show it in a grid dgBooks1.DataSource = objDataSet.Tables(0).DefaultView dgBooks1.DataBind() ' modify a row ' objDataSet.Tables("Employees").Rows(0).Item("FirstName") = "Bob" ' objDataSet.Tables("Employees").Rows(0).Item("LastName") = "Dylan" ' add a new row to the table Dim objTable As DataTable Dim objNewRow As DataRow objTable = objDataSet.Tables("Books") objNewRow = objTable.NewRow() objNewRow.Item("BookName") = "ASP.Net in a Nutshell" objNewRow.Item("ISBN") = "187390145" objTable.Rows.Add(objNewRow) ' save it to a new file objDataSet.WriteXml(Server.MapPath("WroxBooks2.xml")) ' read in the new file Dim objDataSet2 As New DataSet() objDataSet2.ReadXml(Server.MapPath("WroxBooks2.xml")) ' show it in another grid dgBooks2.DataSource = objDataSet2.Tables(0).DefaultView dgBooks2.DataBind() End Sub </script> <html> <head> </head> <body> <table> <tbody> <tr> <td valign="top"> <asp:DataGrid id="dgBooks1" runat="server"></asp:DataGrid> </td> <td valign="top"> <asp:DataGrid id="dgBooks2" runat="server"></asp:DataGrid> </td> </tr> </tbody> </table> </body> </html>


Reply With Quote