Good day, I need some help, I have a dataset which I populate from my db, I also have a xsd Schema file I need to create an xml file using the data from the db and the xsd file.
Can anyone please help me.
All the best
Good day, I need some help, I have a dataset which I populate from my db, I also have a xsd Schema file I need to create an xml file using the data from the db and the xsd file.
Can anyone please help me.
All the best
You can cross reference the database names with the datatable names in you Select Query by using "as" : "Select abc as xyz from table1". "abc" is the database name and xyz is the datatable name which will be the xml tag name.
Here is an example of writing a DataSet
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.IO;
using System.Data;
namespace ConsoleApplication34
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
DataTable dt = new DataTable("MyTable");
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("Id", typeof(int));
dt.Rows.Add(new object[] { "John", 1});
dt.Rows.Add(new object[] { "Mary", 2});
dt.Rows.Add(new object[] { "Dick", 3});
dt.Rows.Add(new object[] { "Harry", 4});
dt.Rows.Add(new object[] { "Jane", 5});
DataSet ds = new DataSet("MySet");
ds.Tables.Add(dt);
ds.WriteXml(FILENAME, XmlWriteMode.WriteSchema);
// or
//ds.WriteXml(FILENAME);
}
}
}