Tuesday, May 5, 2009

Explain 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.

Mostly Used:

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

Example:

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"];

}

No comments:

Post a Comment