DataTable.Columns : DataTable « System.Data « C# / C Sharp by API






DataTable.Columns

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

class PopDataset
{
   static void Main()
   {
      string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";
      string sql = @"select * from employee";
      SqlConnection conn = new SqlConnection(connString);

      try
      {
         conn.Open();
         SqlDataAdapter da = new SqlDataAdapter(sql, conn);
         DataSet ds = new DataSet();    
         da.Fill(ds, "employee");
         DataTable dt = ds.Tables["employee"];
         foreach (DataRow row in dt.Rows)
         {
            foreach (DataColumn col in dt.Columns)
               Console.WriteLine(row[col]);
            Console.WriteLine("".PadLeft(20, '='));
         }
      }
      catch(Exception e)
      {
         Console.WriteLine("Error: " + e);
      }
      finally
      {
         conn.Close();
      }
   }  
}

   
    
  








Related examples in the same category

1.DataTable.Columns.Add
2.DataTable.MinimumCapacity
3.DataTable.NewRow()
4.DataTable.Rows
5.DataTable.Rows.Add