1
Answer

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

Ask a question
Dean

Dean

15y
2.7k
1
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)