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