todonnell69
Member
- Joined
- Jun 8, 2005
- Messages
- 15
- Programming Experience
- 5-10
I'm trying to set up and XmlDataDocument based on the contents of a datagrid, so I can use the .Writeto method to put the data into an xml file.
The XmlDataDocument constructor takes a dataset(Im using datagrid.datasource which works with a ds, but not a dv). Im using a dataview as the datasource of my grid.
Is it possible to convert the dataview to a dataset type to satisfy the xmlDataDocument's constructor?
Thanks for any help!
Tom
The XmlDataDocument constructor takes a dataset(Im using datagrid.datasource which works with a ds, but not a dv). Im using a dataview as the datasource of my grid.
Is it possible to convert the dataview to a dataset type to satisfy the xmlDataDocument's constructor?
Thanks for any help!
Tom
VB.NET:
Dim ds As DataSet = New DataSet
Dim cmd As SqlCommand = cnn.CreateCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT * FROM Customers"
Dim da As SqlDataAdapter = New SqlDataAdapter
da.SelectCommand = cmd
da.Fill(ds, "Customers")
Dim dv As DataView = New DataView(ds.Tables("Customers"))
dv.RowFilter = "Country = '" & txtCountry.Text & "'"
dv.Sort = "CompanyName ASC"
dgCustomers.DataSource = dv
Dim xdd As XmlDataDocument = New XmlDataDocument(dgCustomers.DataSource)
Dim xtw As XmlTextWriter = New XmlTextWriter("c:\temp\Cust.xml", System.Text.Encoding.UTF8)
xdd.WriteTo(xtw)
xtw.Flush()
xtw.Close()
Last edited by a moderator: