Table mapping : DataTableMapping « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.Common;
using System.Windows.Forms;

class MainClass
{
  static void Main(string[] args)
  {
    string ConnectionString ="server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;";
    SqlConnection conn = new SqlConnection(ConnectionString);

    conn.Open();

    try
    {
      DataTableMapping myMapping = new DataTableMapping("Employee", "mapEmployee");
      SqlDataAdapter adapter = new SqlDataAdapter("Select * From Employee",  conn);
      adapter.TableMappings.Add(myMapping);

      DataSet ds = new DataSet();

      adapter.Fill(ds, "mapEmployee");
      Console.WriteLine(ds.Tables[0].ToString());
    }
    catch(SqlException ex)
    {
      Console.WriteLine(ex.Message.ToString());
    }
  }
}








32.40.DataTableMapping
32.40.1.Table mapping
32.40.2.DataTableMapping and DataGridDataTableMapping and DataGrid
32.40.3.ColumnMappings