Click to See Complete Forum and Search --> : Release DB Table from Memory
nbCathy
February 10th, 2004, 12:46 PM
I know what the following lines do:
Dim conStr As String = "Provider=Microsoft.JET.OLEDB.4.0;data source=" & DBFileName
Dim sqlStr As String = "SELECT * FROM " & DBTableName
Dim conn As OleDbConnection = New OleDbConnection(conStr)
Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlStr, conn)
adapter's Fill method
Dim ds As DataSet = New DataSet
da.Fill(ds, DBTable)
But what is the following line do for me?
' Attach dataset's DefaultView to the datagrid control
DataGrid1.DataSource = ds.DefaultViewManager
How do I release the DBTable from memory? It seems as if I fill da. then I can da.dispose but that doesn't work.
Thanks
coolbiz
February 10th, 2004, 09:53 PM
Well, in order for a DATAGRID to display items, the object that you assign to it must have certain characteristics. For example, object that implements IList or IListSource interface such as DataTable, DataView, DataSet, Array and etc.
So if you play w/ you code, you can see that the result is the same with either you assign the DATASET or the DEFAULTVIEWMANAGER of the DATASET.
What is DEFAULTVIEWMANAGER for? Well you need to know what a DATAVIEW is. You need to read MSDN if my explanation is not clear. Basically DATAVIEW allows you to filter through the data in your DATATABLE. This way you can select which records to be displayed on a grid instead of the whole DATATABLE.
DEFAULTVIEWMANAGER (typed as DATAVIEWMANAGER) basically allows you to create DATAVIEW for DATATABLE in the DATASET. Kinda a controller for DATAVIEW from the DATASET level. Make sense?
Now for freeing DATATABLE object. For .NET object, you can check if it exposes .DISPOSE() method. If it does, then you can call this method and if the object is programmed properly, it will dispose/free resources that it uses properly. .DISPOSE() is an implementation of IDISPOSABLE interface. So the common routine to dispose your objects would be like this:
Sub DisposeObject(objToDispose As Object)
Try
' does it implement IDisposable?
If (TypeOf objToDispose Is IDisposable) Then
DirectCast(objToDispose, IDisposable).Dispose()
End If
Catch
End Try
End Sub
So you can pass any object to that routine and it will call Dispose() routine if the object implements IDisposable interface.
-Cool Bizs
nbCathy
February 11th, 2004, 12:30 PM
I'm slow but starting to get 'it'. I did find by running some tests is that I really don't want to dispose of my object datagrid1 but, instead, clear it. ds.clear
Quick question. when printing the table, I want to change the null values to "" but it comes up with error.
Dim chrpos(8) as byte
'TAB Printing
chrpos(0) = 0
chrpos(1) = chrpos(0) + 31
chrpos(2) = chrpos(1) + 8
chrpos(3) = chrpos(2) + 6
chrpos(4) = chrpos(3) + 12
chrpos(5) = chrpos(4) + 16
chrpos(6) = chrpos(5) + 31
chrpos(7) = chrpos(6) + 31
FileOpen(1, AppPath + "TVRI_Results.txt", OpenMode.Append)
Dim t As DataTable
Dim r As DataRow
Dim c As DataColumn
Dim i As integer
For Each t In ds.Tables
For Each r In t.Rows
i = 0
For Each c In t.Columns
If Not (r(c) Is Nothing) Then
if r(c) ="NULL" then r(c)="" 'BOMBS HERE!!!
Print(1, TAB(chrpos(i)), r(c))
End If
i = i + 1
Next
PrintLine(1, "")
Next
Next
FileClose(1)
ds.Clear()
Also, why can't I use the 'c' instead of the i ?
Your help really appreciated, Thanks
coolbiz
February 11th, 2004, 01:53 PM
That should be:
...
If (IsDBNull(r(c))) Then ...
...
Yea, you do not want to DISPOSE your controls. Let FW handles that when you close your form.
-Cool Bizs
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.