Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\test.mdb;"); con.Open(); OleDbCommand cmd = new OleDbCommand("SELECT [add].[stname], [add].[conno] FROM add;", con); OleDbDataAdapter oDA = new OleDbDataAdapter(cmd); DataSet ds1 = new DataSet(); oDA.Fill(ds1); ds1.ReadXmlSchema("Sample.xsd");

here after i got error like type validation schema is not declared

i have one xml schema and access database i need to generate the xml from more than one table fields in this case i can use the queries but after read the queries i displayed that in grid view then i need to generate the xml file which are shown in the gridview using xml schema i have no idea about this.., if anyone have such idea about this means just help me.., thanx in advance..,
Posted
Comments
syed shanu 18-May-14 21:33pm    
Do you want to create a XML file from Dataset?

1 solution

I have make a simple C# Program for you to
1) create a XML file from Dataset
2) To read the XMLSCHEMA to dataset.

// Place 2 Buttons and one Datagireview in your form :

C#
// Declare a Datatable and Function to fill data to datatable : 

 DataTable dt;
        private void fillRows(int pID, string pName, int pPrice)
        {
            DataRow dr;
            dr = dt.NewRow();
            dr["Product_ID"] = pID;
            dr["Product_Name"] = pName;
            dr["product_Price"] = pPrice;
            dt.Rows.Add(dr);
        } 

// In Button1_Click :  fill the dataset and Datagridview and create XML file 

 private void button1_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            dt = new DataTable();
            dt.Columns.Add(new DataColumn("Product_ID", Type.GetType("System.Int32")));
            dt.Columns.Add(new DataColumn("Product_Name", Type.GetType("System.String")));
            dt.Columns.Add(new DataColumn("product_Price", Type.GetType("System.Int32")));
            fillRows(1, "product1", 1111);
            fillRows(2, "product2", 2222);
            fillRows(3, "product3", 3333);
            fillRows(4, "product4", 4444);
            ds.Tables.Add(dt);
            ds.Tables[0].TableName = "product";
            ds.WriteXml(@"D:\Product.xml");
            MessageBox.Show("Done");
            dataGridView1.DataSource = ds.Tables[0];
            
        }
// In Button2_Click :  Read the XMLSchema to dataset : 

  private void button2_Click(object sender, EventArgs e)
        {
            DataSet thisDataSet = new DataSet();
            // Set the file path and name. Modify this for your purposes. 
            string filename = @"D:\Product.xml";
            // Create a FileStream object with the file path and name.
            System.IO.FileStream stream = new System.IO.FileStream
                (filename, System.IO.FileMode.Open);
            // Create a new XmlTextReader object with the FileStream.
            System.Xml.XmlTextReader xmlReader =
                new System.Xml.XmlTextReader(stream);
            // Read the schema into the DataSet and close the reader.
            thisDataSet.ReadXmlSchema(xmlReader);
            xmlReader.Close();
            dataGridView1.DataSource = thisDataSet.Tables[0];

        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900