Home
Manage Your Code
Snippet: SqlDataReader (C#)
Title: SqlDataReader Language: C#
Description: simple SqlDataReader code in a class that returns a SqlDataReader. The connection string is stored in the web.config file Views: 154
Author: Richard Mueller Date Added: 10/7/2007
Copy Code  
1        public SqlDataReader GetDivisions(string sqlConn) {
2            SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings[sqlConn]);
3
4            strSQL = "Select * from Divisions Where Status = 'A' order by SortOrder, DIV";
5            cn.Open();
6            SqlCommand cmd;
7            SqlDataReader rdr;
8            cmd = new SqlCommand(strSQL, cn);
9            rdr = cmd.ExecuteReader();
10	    cn.Close()
11
12            return rdr;
13        }
14
Usage
Use this code in a class that is called to return a datareader