Help me understand the behavior of this code.
[Mystery #1]
If I run code 1 (below) the datagrid stays populated.
=== incidental code ===
Private dataSet1 As CLIP.dsTables
private Sub FillDataSet()
Dim DAL As New CLIP.DataAccess
DAL.daJob.Fill(dataSet1, "tblJob")
Me.DataGrid1.DataMember = "tblJob"
Me.DataGrid1.DataSource = dataSet1
End Sub
============
=== code 1 ===
Private Sub btnTestReload_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnTestReload.Click
Me.DataGrid1 = Nothing
Dim dataset1 As New CLIP.dsTables
Dim myTable As New DataTable
myTable.Clear()
End Sub
============
[Mystery #2]
But, if I run code 2 the datagrid is cleared why?
=== code 2 ===
Private Sub btnTestReload_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnTestReload.Click
Me.DataGrid1 = Nothing
Dim dataset1 As New CLIP.dsTables
Dim myTable As New DataTable
ClearTable(myTable)
End Sub
Private Sub ClearTable(ByVal myTable As DataTable)
myTable.Clear()
End Sub
============
[Mystery #3]
If I run code 3 after either of these I get an error
=== Code 3 ===
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Call LoadDataInForm() 'The same code that the form_load uses to load
the data into the datagrid
End Sub
====
[Mystery #3 continued]
The error occurs during the datagrid load on these lines
Me.DataGrid1.DataMember = "tblJob"
Me.DataGrid1.DataSource = dataSet1
The error is a null reference exception. But why??? DataTable Clear
does not destroy the table just remove the rows. Any explaination?
---
Doug