What is DataReader Object?

It provides a forward-only, read-only, connected recordset.

It is most efficient to use when data need not to be updated, and requires forward only traverse. In other words, it is the fastest method to read data.

Example:

1. Filling dropdownlistbox.
2. Comparing username and password in database.

SqlDataReader rdr = cmd.ExecuteReader();

//Reading data

while (rdr.Read())
{

//Display data

string contact = (string)rdr["ContactName"];
string company = (string)rdr["CompanyName"];
string city = (string)rdr["City"];

}

Comments

Popular posts from this blog

How do I calculate a MD5 hash from a string?

What is WSDL?