Question : SqlDataReader

I get following error from a code in code behind:

"The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined"

What am I doing wrong?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
SqlDataReader reader1=new SqlDataReader();
if (type == 1)
{                           
reader1=projectDb.GetProjectByAuthor(authorId)        
}
else if (type == 2)
{
reader1 = projectDb.GetAllProjects()
}

Answer : SqlDataReader

To your statement:,

"Then I get an error:
Use of unassigned local variable 'reader1'
The error happens in the line:
while (reader1.Read())"

The, Use of unassigned local variable 'reader1', is not an error, it should be reported as a Warning. To remove the Warning modify the statement to this:

SqlDataReader reader1 = null;  // Will remove the warning

Random Solutions  
 
programming4us programming4us