Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SqlDataReader Data Class Question
Message
 
To
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:
00956734
Views:
7
Randy;

You gave me a great idea. A bit of playing with words (syntex) and it works fine! My VB.NET version works. There is something different about VB.NET and C sharp in this instance. I will have to look into what is going on. Now I ahve to convert the rest of my application from VB.NET to C sharp.

Tom


>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() ;
>	
>		}
>
>}
>
>
>
>
>
Previous
Reply
Map
View

Click here to load this message in the networking platform