Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SqlDataReader Data Class Question
Message
From
27/10/2004 13:34:36
 
General information
Forum:
ASP.NET
Category:
Web forms
Environment versions
Environment:
C# 1.1
OS:
Windows 2000 SP3
Network:
Windows 2000 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
00954923
Message ID:
00954939
Views:
8
This message has been marked as the solution to the initial question of the thread.
Hey Thomas, the close reader will not run because it is after the return statement. you can do one of two things. store the data from the read into a variable then close the read and return the variable. Or create another method to close the reader and call it after you finish using it in your program.
public class ScrapDB
	{
             public sqldatareader UsersReader

		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 ;
				
				
			
		

			}
		public static CloseReader()
		{
		        UsersReader.Close() ;
	
		}

}
Randy Belcher
AFG Industries, Inc.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform