Here we will use SqlDataReader to learn the use of Data Reader in data access code of ASP.Net with C#. For using SqlDataReader object you have to code little bit more than the code for DataSet. You also have to work according to the following guidelines to make your code managed and in-control:
/// <summary> /// connection string retrieved from /// web.config connectionstring section /// </summary> string connectionString = ConfigurationManager.ConnectionStrings[ "NorthwindConnectionString" ].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connectionString);
sqlConn.Open();
SqlCommand sqlCmd = new SqlCommand(sql, sqlConn);
SqlDataReader sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
You can use the data reader obtained by ExecuteReader method of SqlCommand:
Be the first to rate this post
Tags: asp.net, ado.net, asp.net performance, ado.net performance, dataset, data reader, sqldatareader, data access
7/24/2008 5:23:49 PM