Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SqlDataReader Data Class Question
Message
De
27/10/2004 13:34:36
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires Web
Versions des environnements
Environment:
C# 1.1
OS:
Windows 2000 SP3
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
00954923
Message ID:
00954939
Vues:
9
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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform