Fill a DataTable using DataAdapter : 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 ContactID, FirstName, LastName FROM Person.Contact";

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

            foreach (DataRow row in dt1.Rows)
            {
                Console.WriteLine(
                    "ContactID = {0}\tFirstName = {1}\tLastName = {2}",
                    row["ContactID"], row["FirstName"], row["LastName"]);
            }
        }
    }








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