Problems persisting a datatable between forms in an interop dll

  • 12 years ago

     For test purposes, i have first created my program as a standalone exe project and everything works fine.  When i re-create the project as an interop dll, i get an error.

    In both projects, i create a datatable in a module file with the following code
     

    Friend SelectedHistoryTable As DataTable

    Form1 is called from FoxPro via interop.

    Form1 then calls Form2 which adds the column names to the table

    SelectedHistoryTable = New DataTable("SelectedHistory")

            Dim DateTimeCol As New DataColumn("DateTime")
            SelectedHistoryTable.Columns.Add(DateTimeCol)

            For j As Integer = 0 To lstTags.Items.Count - 1
                Dim NewTagCol As New DataColumn(lstTags.Items.Item(j).ToString())
                SelectedHistoryTable.Columns.Add(NewTagCol)
            Next j

    Form1 then calls Form3 which adds data to the table

     Dim NewRow As DataRow
                NewRow = SelectedHistoryTable.NewRow()

     
    This works fine as a standalone app, but i cant get this section of code working when i am compiling it as a dll.

     The last line (that creates the newrow) causes a NullReferenceException

    Object reference not set to an instance of an object.

    I can't see why this table does not have scope on this form in the dll project but it does in the standalone project.

     

    Can anyone help?

     

     

     

     

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” - Martin Fowler