Opening-Closing Connection Question

S

Steve

Hello,
Let's say I open a form and populate a grid and a few textboxes with a
dataset, something like this (I won't go into detail, because the code does
work, I just don't know how streamlined it is):

Form Load
Dim DataSet
Dim Connection
Open Connection
Setup DataAdapter
Fill DataSet
Bind grid and textboxes
Close Connection

Now say I make a few changes, and after every change I want to write the
change back to the database (These changes can be minutes apart, so waiting
to update all at once is not what I want to do). Do I need to repeat all the
steps from the Form Load Procedure (minus the binding parts)? So if I have a
button that updates the database, it would be something like:

Button_Click
Dim Connection
Dim DataAdapter
Setup DataAdapter
Dim CommandBuilder
Setup CommandBuilder
Open Connection
Dim DataSet
Fill DataSet
Make Changes
Update DataAdapter
Close Connection

Now, this works fine, but I just don't know if I'm wasting resources, or
slowing my program down by doing this, because I'm going to have to do this
alot throughout my forms. Thanks to anyone in advance.

Steve
 
S

Scott M.

You could close the connection but not destroy it. Remember that in ADO.NET
you are working with disconnected data for better efficiency. Once the data
has been updated, you could re-open your connection and call update on your
dataAdapter.
 
P

Peter Huang

Hi Steve,

I agree with Scott's suggestion.
Usually we manipulate the dataset as the DataSouce, so that we can free the
resource on the Database server and the network resource(if you connect to
database on another computer)

Here is a link about dataset, you may take a look.
313485 INFO: Roadmap for ADO.NET DataSet, DataView, and DataViewManager
Objects
http://support.microsoft.com/?id=313485

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top