using System;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
class MainClass
{
static void Main(string[] args)
{
string ConnectionString ="server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI;";
string SQL = "SELECT * FROM Employee";
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand(SQL, conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
Console.WriteLine("ID, FirstName");
while (reader.Read())
{
Console.Write(reader["ID"].ToString() + ", ");
Console.Write(reader["FirstName"].ToString() + ", ");
}
Console.WriteLine("Total Number of records affected: "+ reader.RecordsAffected.ToString() );
reader.Close();
conn.Close();
}
}
|