Data binding using DataReader in ASP.Net

Data binding using DataReader in ASP.Net


//Data Access using DataReader
try
{
//Make a connection to database
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["DashboardConnectionString"]);
string cmdtext = "select EmployeeNo,Name,Email from tab1";
conn.Open();
SqlCommand cmd = new SqlCommand(cmdtext, conn);
//Excute query
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
//do something here
}

}
catch (Exception ex)
{
Response.Write(ex.Message);

}


Comments

Author: Kiran05 Aug 2009 Member Level: Bronze   Points : 1

Good, It helped me a lot.

Thanks,
Kiran



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: