public class ScrapDB { public SqlDataReader oReader; protected SqlConnection oConnection; // Constructor public ScrapDB() { oConnection = this.GetConnection(); } public SqlConnection GetConnection() { string connectionString = ConfigurationSettings.AppSettings["connectionString"]; return new SqlConnection(connectionString); } public void GetUsers() { string selectStatement = "SELECT UserID " + "FROM UserInfo "; SqlCommand selectCommand = new SqlCommand(selectStatement, this.oConnection); this.oConnection.Open(); this.oReader = selectCommand.ExecuteReader(CommandBehavior.CloseConnection); this.oReader.Read() ; } }A call to GetUsers would simply open your connection and set up the Reader. You would then use the public oReader in your UI to read in your data. You'd also need to use oReader.Close() to close the Reader and the Connection. Again, this is just off the top of my head and there may be some problems with this code, but I think it's enough to maybe get you going in this direction. Since I haven't used DataReaders, I may be off on a coupla things. =)
>public class ScrapDB > { > > public static SqlConnection GetConnection() > { > string connectionString = ConfigurationSettings.AppSettings["connectionString"]; > > return new SqlConnection(connectionString); > > } > > public static SqlDataReader GetUsers() > { > // Use a SqlDataReader to fill ddlUsers... > SqlDataReader UsersReader = null ; > > SqlConnection UsersConnection = GetConnection() ; > > string selectStatement = "SELECT UserID " > + "FROM UserInfo "; > > SqlCommand selectCommand = new SqlCommand(selectStatement, UsersConnection); > //SqlDataReader UsersReader; > > UsersConnection.Open(); > UsersReader = selectCommand.ExecuteReader(CommandBehavior.CloseConnection); > UsersReader.Read() ; > return UsersReader ; > > > UsersReader.Close() ; > > > > } >} > > > >>