473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

NullReferenceException problem working with Dataset

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(Accou ntID);
}
catch
{
MessageBox.Show("NullReferenceException in getting data');
}
The code that causes the NullReferenceException is:

ds = scheduleDomainController1.GetScheduleDataSet(Accou ntID);

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

May 5 '06 #1
2 1764
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"eljainc" wrote:
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(Accou ntID);
}
catch
{
MessageBox.Show("NullReferenceException in getting data');
}
The code that causes the NullReferenceException is:

ds = scheduleDomainController1.GetScheduleDataSet(Accou ntID);

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

May 5 '06 #2
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

May 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Fabio Papa | last post by:
Hi, I am fairly new to programming and and even newer to dotnet. I appoligise in advance if this is a dumb questions, and I would appreciate if you could answer it anyways. :) I am writing a...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
3
by: Mico | last post by:
I would be very grateful for any help with the following problem: I use a DataAdapter to fill a DataSet in the Page_Load method. Later, I use this DataSet to construct a DataTable, then create...
3
by: postings | last post by:
Hi Can anybody help? (ASP.NET 1.1) The event below is triggered when the user clicks an update button column. I am trying to update a dataset which eventually gets bound with a datagrid,...
2
by: Michael Murschell | last post by:
When I close my application, it always gives me this error at line... MyBase.Dispose(disposing) The error... An unhandled exception of type 'System.NullReferenceException' occurred in...
1
by: Craig | last post by:
This is killing me, I've been trying to figure this out for 2 days. When I click on the linkbutton, it executes the GetData(int) method to set the DataSource. The FAILURE is when it tries to...
5
by: ducky801 | last post by:
Hi all. When i run the code below i get a 'NullReferenceException was unhandled' error. I am using VB 2005 Express. I'm confused about this because, I have declared my array and i'm trying to...
0
by: schoultzy | last post by:
Hello Everyone, I have been trying to figure this one out for two days now. I have created a DataGridView which is populated by an ObjectDataSource. My problem occurs when I attempt to use the...
2
by: nospam | last post by:
I have code that is working in one place but not another. In one spot, you click a button to open an XML file and have it read into a dataset. I then set the datasource of my datagrid to the...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.