NullReferenceException problem working with Dataset

  • Thread starter Thread starter eljainc
  • Start date Start date
E

eljainc

Hello,

I'm pretty new to C# programming, so be gentle with me. I have a block
of code which is the following:



scheduleDomainController1.ConnectionString = "data
source=.\\SQLEXPRESS;"+
"database=MyDatabase;Trusted_Connection=True;";


string AccountID = "00000000-0000-0000-0000-000000000000";

DataSet ds;
ds = new DataSet();
try
{
ds = scheduleDomainController1.GetScheduleDataSet(AccountID);
}
catch
{
MessageBox.Show("NullReferenceException in getting data');
}


The code that causes the NullReferenceException is:

ds = scheduleDomainController1.GetScheduleDataSet(AccountID);

scheduleDomainController is a component which allows one to connect
to a SQL database with minimal effort.

I am sure that the scheduleDomainController1 object has been created.
What else could cause this exception?

Thanks
Mike McWhinney
 
eljainc,
The code you present in your post is always going to show you a null
referenceException since you aren't even catching an instance of the
Exception object. Try revising it to something like this to get more valuable
info:


catch (Exception ex)
{
MessageBox.Show(ex.Message +ex.StackTrace);
}


-- Now you will be able to see what really happened, and where.
Peter
 
Thanks Peter for the programming correction.

However my code still reports an exception. It gives *more* detailed
information however (the offending line number). The exception
basically says, if I understand correctly, that that the object
dataSet1 has been created but not initialized with new(). It has been
created though. This is what stumps me.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top