using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace SelectIntoDataSet {
	class Program {
		static void Main (string[] args) {
			String connectionString = "server=localhost;database=AdventureWorks;uid=sa;pwd=dbadmin";
			SqlConnection connection = new SqlConnection (connectionString);
			
			String query =
				"SELECT TOP 10 Title, FirstName, LastName, EmailAddress " +
				"FROM Person.Contact " +
				"ORDER BY ContactID";
			SqlCommand command = connection.CreateCommand ();
			command.CommandText = query;

			SqlDataAdapter dataAdapter = new SqlDataAdapter ();
			dataAdapter.SelectCommand = command;
			
			DataSet dataSet = new DataSet ();

			connection.Open ();
			dataAdapter.Fill (dataSet, "Person.Contact");
			connection.Close ();

			DataTable dataTable = dataSet.Tables["Person.Contact"];
			foreach (DataRow dataRow in dataTable.Rows) {
				Console.WriteLine (dataRow["Title"] + " " + dataRow["FirstName"] + " " +
					dataRow["LastName"] + ", " + dataRow["EmailAddress"]);
			}

			Console.ReadLine ();
		}
	}
}
