473,326 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Mysteries when clearing a data table?

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

Nov 21 '05 #1
2 1943

"dbuchanan" <db*********@hotmail.com> wrote in message
news:11********************@g43g2000cwa.googlegrou ps.com...
[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?


You are destroying the reference to your datagrid in your earlier code with
Me.DataGrid1 = Nothing

If you want to remove the datasource from your datagrid use
Me.DataGrid1.datasource = Nothing

I think that could be the answer to mysteries 1-3

hth
Steve
Nov 21 '05 #2
Thank you that was it.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: rmatteson | last post by:
I am trying to figure out how to clear all items from a combobox (Access 2002). On my form, I have to comboboxes. Combobox 2 is populated with a set of child data dependent on the parent data...
3
by: RSH | last post by:
Hi, I have a situation where I have a datagridview on a form. I am making a dynamic table editor where users select a database table and then it calls this function where the data in the...
3
by: Darin | last post by:
I have a problem I just can't figure out. I have a form with a subform, and the recordsource of the subform has criteria based on some unbound fields in the parent form so that data in the parent...
5
by: Bill Jackson | last post by:
What is the benefit of clearing a dictionary, when you can just reassign it as empty? Similarly, suppose I generate a new dictionary b, and need to have it accessible from a. What is the best...
3
by: Angel Blue01 | last post by:
I have a form with a binding navigator that draws from a database via drag-and-drop-created controls. I'm filling a listbox with the results of a query. The listbox contains data related to the...
2
by: notsosavy | last post by:
Each month I will be updating a table in my database using data from a spreadsheet. I thought that I could just Copy/Paste from the spreadsheet and Ctrl A/Ctrl V and paste the info into the table. ...
1
by: hathan | last post by:
I am using the code below to connect to a Access database and the first time roumd it works perfectly but then it errors. I think that the datatable might need clearing but i dont no how to do this....
1
by: Esteban404 | last post by:
//using C# 2005, MS SQL 2000(prod) and SQL Express 2005 (dev) My sprocs all have a clearing mechanism at the end like this for each temporary table I use: --drop temporary tables IF...
176
by: . | last post by:
9/11 Mysteries http://video.google.com/videoplay?docid=-8172271955308136871 http://www.911weknow.com Ignore those who would go to great effort and expend much of heir time in poo-pooing this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.