using System;
using System.Data;
using System.Data.Common;
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 TOP 5 Title, FirstName, LastName FROM Person.Contact";
SqlDataAdapter da = new SqlDataAdapter(sqlSelect, sqlConnectString);
DataTableMapping dtm = da.TableMappings.Add("Table", "myContact");
dtm.ColumnMappings.Add("Title", "myTitle");
dtm.ColumnMappings.Add("FirstName", "myFirstName");
dtm.ColumnMappings.Add("LastName", "myLastName");
DataSet ds = new DataSet();
da.Fill(ds);
Console.WriteLine("DataTable name = {0}",ds.Tables[0].TableName);
foreach(DataColumn col in ds.Tables["myContact"].Columns)
{
Console.WriteLine(col.Ordinal);
Console.WriteLine(col.ColumnName);
}
foreach(DataRow row in ds.Tables["myContact"].Rows)
{
Console.WriteLine(
"Title = {0}, FirstName = {1}, LastName = {2}",
row["myTitle"], row["myFirstName"],
row["myLastName"]);
}
}
}