I'm currently putting together a desktop application and trying to make a data table (called DT_series) that's declared in my startup class (main) accessible to any other forms in the project. This is what I've declared in main:
namespace RMA
{
public partial class Main : Form
{
public DataTable DT_series;
.......
public Main()
{
InitializeComponent();
DT_series = new DataTable();
............
and in another form, I have, for example, this section of code that fills the table with something:
Main.DT_series = dbobj.GetSeries((string)this.lstDrvMan.SelectedValue);
There are no build errors, but when I run the code, it crashes at the above line with this error:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
It's complaining about the existence of DT_series, but I thought that the way I declared it in main, it's public, and instantiated, so the other form should be able to talk to it. Can anyone tell me where I've gone wrong? Thanks.
How do you make a data table accessible anywhere in a Visual C# 2008 Express project?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Mahesh ChandRank #1 · 393.4K reputationPosted Mar 28, 2009, 9:17 AM EDT
Check your right side of "=" code. Error may be in the right side. Your reference to Main.DT_Series looks ok.
Main.DT_series = dbobj.GetSeries((string)this.lstDrvMan.SelectedValue);