I have the following code which is supposed to create an xml from a dataset but is not working. can you help me please.
If SaveFileDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
Try
Dim MyFile As FileStream = New FileStream(SaveFileDialog.FileName, FileMode.Create)
Dim NewFile As MemoryStream = New MemoryStream
cheroDataset.WriteXml(NewFile)
Dim NewData(NewFile.Length) As Byte
NewFile.Read(NewData, 0, NewData.Length)
MyFile.Write(NewData, 0, NewData.Length)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
Scott LyslePosted Feb 19, 2008, 3:18 AM
With WriteXml you can just pass it a path to where you want the file stored: (e.g. the following code gets a dataset and then stores the xml into the file specified in the path argument)
using (SqlConnection conn = new SqlConnection(Properties.Settings.Default.ConnStr)) { string sSql = "SELECT * FROM Points"; conn.Open(); SqlCommand command = new SqlCommand(sSql, conn); SqlDataAdapter da = new SqlDataAdapter(command); DataSet ds = new DataSet(); da.Fill(ds); ds.WriteXml(@"c:\Temp\junkXML.xml"); }