Fill a DataSet using DataAdapter and output to console : DataAdapter « ADO.Net « C# / CSharp Tutorial






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

    class Program
    {
        static void Main(string[] args)
        {
            string sqlConnectString = "Data Source=(local);Integrated security=SSPI;Initial Catalog=AdventureWorks;";

            string sqlSelect = "SELECT FirstName, LastName FROM Person.Contact";

            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, sqlConnectString);
            DataTable dt = new DataTable( );
            da.Fill(dt);

            foreach (DataRow row in dt.Rows)
                Console.WriteLine("{0} {1}", row[0], row["LastName"]);


            DataSet ds = new DataSet( );
            da.Fill(ds, "Contact");

            Console.WriteLine(ds.Tables.Count);
            Console.WriteLine(ds.Tables[0].TableName);
            foreach (DataRow row in ds.Tables["Contact"].Rows)
                Console.WriteLine("{0} {1}", row[0], row[1]);
        }
    }








32.32.DataAdapter
32.32.1.Multiple DataAdapter
32.32.2.Update through SqlDataAdapter
32.32.3.Fill a DataSet using DataAdapter and output to console
32.32.4.Fill a DataTable using DataAdapter
32.32.5.Use a DataAdapter to fill a DataTable