Dean

Dean

  • NA
  • 3
  • 0

How do you make a data table accessible anywhere in a Visual C# 2008 Express project?

Mar 28 2009 3:15 AM
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.




Answers (1)