Read data from DataSet : DataSet : Database C# Source Code


Custom Search

C# Source Code » Database » DataSet »

 

Read data from DataSet








    


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();
      }
   }  
}


           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Database
» DataSet