How to Read data with SqlDataReader Object in ADO.Net?

How to Read data with SqlDataReader Object in ADO.Net?

SqlDataReader rdr = cmd.ExecuteReader();
The typical method of reading from the data stream returned by the SqlDataReader is to iterate through each row with a while loop.
while (rdr.Read())
{
string conta = (string)rdr["ContactName"];
string comp = (string)rdr["CompanyName"];
string cty    = (string)rdr["City"];
Console.Write("{0,-25}", conta);
Console.Write("{0,-20}", cty);
Console.Write("{0,-25}", comp);
Console.WriteLine();
}

By:Aditya
Date:2028-10-10 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related ADO.NET Subjective Links

ADO.NET Subjective interview questions and answers for experienced and fresher