Wednesday, 12 August 2015

What is return type of ExecuteReader in C#.Net

The return type of ExecuteReader method is DataReader.

Example of DataReader : 

 static void GetData(SqlConnection conn)
{
    using (connection)
    {
        SqlCommand command = new SqlCommand("SELECT EmpName,Salary,Location FROM Employee;",
          conn);
        connn.Open();

      System.Data.SqlDataReader reader = command.ExecuteReader();

        if (reader.HasRows)
        {
            while (reader.Read())
            {
                Console.WriteLine("{0}\t{1}", reader.GetInt32(0),
                    reader.GetString(1));
            }
        }
        else
        {
            Console.WriteLine("No rows found.");
        }
        reader.Close();
    }
}



No comments:

Post a Comment