Read schema and reload data with DataSet : DataSet « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.SqlClient;

public class SaveDataSet
{
    private static string connectionString = "Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI";

    public static void Main() 
    {
        string SQL = "SELECT CategoryID, CategoryName,Description FROM Categories";

        SqlConnection con = new SqlConnection(connectionString);
        SqlCommand com = new SqlCommand(SQL, con);
        SqlDataAdapter adapter = new SqlDataAdapter(com);
        DataSet ds = new DataSet("Nortwind");

        con.Open();
        adapter.FillSchema(ds, SchemaType.Mapped, "Categories");
        adapter.Fill(ds, "Categories");
        con.Close();

        ds.WriteXmlSchema("mydata.xsd");
        ds.WriteXml("mydata.xml");

        ds.Reset();


        ds.ReadXmlSchema("mydata.xsd");
        ds.ReadXml("mydata.xml");

        Console.WriteLine(ds.GetXml());
    }
}








32.35.DataSet
32.35.1.Simple Query Dataset
32.35.2.Fill a DataSet
32.35.3.Find Rows In Data
32.35.4.Load XML to DataSet
32.35.5.DataSet Merge event
32.35.6.Merge two DataSet
32.35.7.Creating a Strongly Typed DataSet
32.35.8.DataSet Read with SqlDataAdapter
32.35.9.DataSet.DataTable count
32.35.10.DataSet.DataTable name
32.35.11.Mapping Table and Column Names Between a Data Source and DataSet
32.35.12.Retrieving Schema and Constraints for a DataSet
32.35.13.Read schema and reload data with DataSet
32.35.14.Navigating Between Parent and Child Tables in an Untyped DataSet
32.35.15.Multitabled DataSet App