Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following method :

C#
private void SetModuleOrPageByUserId(int userId)
       {
           ViewReports vr = new ViewReports();
           SqlDataReader drUserPref = null;
           drUserPref = vr.SetModuleOrPageByUserId(Convert.ToInt32(Session["UserID"]));
           if (drUserPref != null && drUserPref.HasRows)
           {
               while (drUserPref.Read())
               {
                   if (drUserPref["DefaultPage"] != null && drUserPref["ModuleName"] != null)
                   {
                       pageNameToRedirect = drUserPref["DefaultPage"].ToString();
                       moduleName = drUserPref["ModuleName"].ToString();
                   }
               }
           }
       }

What difference will it make if i declare the drUserPref as
C#
SqlDataReader drUserPref = null
OR
C#
SqlDataReader drUserPref = new SqlDataReader();
Posted
Updated 14-Mar-12 21:44pm
v3

1 solution

You cannot instantiate an instance of SqlDataReader using the new keyword, as the data reader has no constructors. You have to create an instance using ExecuteReader on the command. This is by design SqlDataReader (MSDN)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900