Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Object reference not set to an instance of an object.
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01454270
Message ID:
01454349
Vues:
31
>>>What's wrong with this?
>>>
>>>
>>>public partial class crlRoles : System.Web.UI.UserControl
>>>{
>>>    private DataSet dsRoles = null;
>>>    private DataAccess DataLayer = null;
>>>
>>>    protected void Page_Load(object sender, EventArgs e)
>>>    {
>>>        if (!IsPostBack)
>>>        {
>>>            dsRoles = new DataSet();
>>>            DataLayer = new DataAccess();
>>>            DataLayer.ConnectionString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
>>>
>>>            _LoadList();
>>>        }
>>>    }
>>>
>>>    private void _LoadList()
>>>    {
>>>
>>>        dsRoles = DataLayer.ExecuteQuery("as_GetRole", CommandType.StoredProcedure);
>>>
>>>        lstRoles.DataSource = dsRoles.Tables[0];
>>>        lstRoles.DataMember = "RoleName";
>>>    }
>>>}
>>>
>>>
>>>I have tried moving the instantiations into _LoadList, and it still fails.
>>
>>That wouldn't be the problem anyway.
>>
>> DataLayer is an object. dsRoles is null. When I run the
>>>ExecuteQuery line it errors.
>>
>>So what's the error ?
>
>"Object reference not set to instance of an object"

Are you sure the error is on the .ExecuteQuery() line?
Obviously C# doesn't care whether dsRoles is null or not at that point (in fact you don't need to instantiate dsRoles in the crlRoles class at all).
Have you tried stepping through the ExecuteQuery() method? If, for example, the DataAccess class is in a different assembly without debugging or the method is marked with [DebuggerStepThrough] then you would see what you're seeing if the error was, in fact, in that code.
Look at the TargetSite in the Debugger detail. Is that showing Page_Load or ExecuteQuery ?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform