Sorry for the vauge title, it's a bit tricky to summarize in a line!
Basically I have written a class which will be responsible for my SQL transactions.
Within the class there is a function which you parse a query string to, the function will connect to the DB, execute the query and return the data as a datatable to the caller.
I have to create a new instance of a datatable everytime the function is called, if not the returned data (as a datatable) seems to point to the same place, so if I was to fill a datagridview it will populate fine, but then if i use the same function to populate another datagridview using a different query, the data will be lost in the first datagridview, but the schema still remains.
So here is a simple version of the code to explain it a little easier.
I just typed the above quickly to help explain my question.
If I was to click button 1, say 10000 times, what happens to all those 'new objects' created in the function? Do they get removed by the garbage collector?
Sorry it's a little vauge , if its confusing I can try and re-explain
Is there a better way to do this? What I have works fine, I just wanted to check that it's 'aceptable' as I haven't used datatables much.
Thanks!
Basically I have written a class which will be responsible for my SQL transactions.
Within the class there is a function which you parse a query string to, the function will connect to the DB, execute the query and return the data as a datatable to the caller.
I have to create a new instance of a datatable everytime the function is called, if not the returned data (as a datatable) seems to point to the same place, so if I was to fill a datagridview it will populate fine, but then if i use the same function to populate another datagridview using a different query, the data will be lost in the first datagridview, but the schema still remains.
So here is a simple version of the code to explain it a little easier.
VB.NET:
myClass
Function SQLquery(data)
dim myDT as new datatable
myDT=getSQLdata
return DT
end function
end Myclass
** form code **
dim myObj as new myclass
sub button1_click
datagridview1.datasource = myobj.SQLquery("select * from table")
end sub
I just typed the above quickly to help explain my question.
If I was to click button 1, say 10000 times, what happens to all those 'new objects' created in the function? Do they get removed by the garbage collector?
Sorry it's a little vauge , if its confusing I can try and re-explain
Is there a better way to do this? What I have works fine, I just wanted to check that it's 'aceptable' as I haven't used datatables much.
Thanks!