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.
Loading
Mahesh ChandPosted Mar 28, 2009, 1:17 PM
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);