i think it would be easier for you to use this approach:
Code:
using System;
using System.Data.SqlClient;
public class Test
{
public static void Main()
{
Test t=new Test();
t.Run();
}
public void Run()
{
SqlConnection conn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI; Initial Catalog=pubs");
SqlCommand cmd = new SqlCommand("SELECT * FROM emp_test", conn);
try
{
conn.Open();
SqlDataReader myReader = cmd.ExecuteReader();
Console.WriteLine("Code \t Emp. Name \t Emp. Phone");
Console.WriteLine("-----------------------------------------");
while (myReader.Read())
{
Console.WriteLine("{0}\t{1}\t\t{2}", myReader.GetInt32(0), myReader.GetString(1), myReader.GetString(2));
}
myReader.Close();
conn.Close();
}
catch(Exception e)
{
Console.WriteLine("Exception Occured -->> {0}",e);
}
}
}