.NET Datatable usage question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greeting
I have a .net Windows application with a procedure that loads some comboboxes from SQL server. I make the connection to SQL with SQLconnection object, run a command against this Object and load the results to a DataTable object
My question is will the datatable object still store the resultset if I end the procedure with a SQLconnection.close, thus allowing the user to run in a disconnected state, with the data in the comboboxes cached in the dataTable objects? When is the Datatable object destroyed? On a redim or closed connection? What I would like to do is get into the DB, get the data for the form controls, get out of DB, and stay out until the app is reloaded. Thanks all
 
<<My question is will the datatable object still store the resultset if I
end the procedure with a SQLconnection.close, thus allowing the user to run
in a disconnected state, with the data in the comboboxes cached in the
dataTable objects?>>

Yes, assume that you declared a DataTable at the module level, then
instantiated it in Form_Load. Assume you call dataadapter.fill(DataTable)
in load and your datatagble has 25 rows. You can refer to it anywhere in
the code and DataTable will have 25 rows. You can bind it using
ComboBox.DataSource = DataTable
ComboBox.DisplayMember = "FieldNameYouWantShownInComboBox"
ComboBox.ValueMember = "FieldYouWnateSelectedValueToReturn"

The DataAdapter automatically opens and closes the connection, so it doesn't
matter after fill is closed (but, IF you open it manually, make sure you
close it immediately).

A dataReader on the other hand can't do anything after the connection is
closed. Totally different object and methodology though.
<<When is the Datatable object destroyed? >> When it goes out of scope, is
destroyed/and or garbage collected. You won't be able to access it anymore
once it goes out of scope or an object with a reference to it isn't visible
anymore.


<<On a redim or closed connection?>> Not sure what Redim means, but no,
closing the connection has no bearing.
<<What I would like to do is get into the DB, get the data for the form
controls, get out of DB, and stay out until the app is reloaded. >> That's
precisely what DataTables/DataAdapters give you. The example above will do
it for you..

HTH,

Bill

Eric said:
Greetings
I have a .net Windows application with a procedure that loads some
comboboxes from SQL server. I make the connection to SQL with SQLconnection
object, run a command against this Object and load the results to a
DataTable object.
My question is will the datatable object still store the resultset if I
end the procedure with a SQLconnection.close, thus allowing the user to run
in a disconnected state, with the data in the comboboxes cached in the
dataTable objects? When is the Datatable object destroyed? On a redim or
closed connection? What I would like to do is get into the DB, get the data
for the form controls, get out of DB, and stay out until the app is
reloaded. Thanks all
 
Back
Top