Well they are not exactly the same.The difference doesn't have to do with the reader you're using though. The difference between the two code blocks is that one is using a while loop and the other is a method. To make them the same they would look like these
First Block
protected void ReadReader(SqlDataReader rdr)
{
while (rdr.Read())
{
// get the results of each column
string contact = (string)rdr["ContactName"];
string company = (string)rdr["CompanyName"];
}
} Second Block
protected void ReadReader(IDataReader rdr)
{
while (rdr.Read())
{
// get the results of each column
string contact = (string)rdr["ContactName"];
string company = (string)rdr["CompanyName"];
}
} I like the second block better simply because you call them both using the same code, but the second one is not forcing you to continue using the SqlDataReader. It will allow you to change later on. You call the functions using the following code.
ReadReader(myReader);
My reader could either be a SqlDataReader or an IDataReader of any kind for that matter.
I hope that makes sense,
Brendan
C. Brendan Enrick
Brendan's BlogMake sure you click "Mark as Answer" for any post which has helped you. This will give recognition to those helping others as well as earn you a point. It also helps people know which posts still need work.