473,466 Members | 1,363 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Opening-Closing Connection Question

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


Nov 20 '05 #1
2 1148
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.

"Steve" <be******@ix.netcom.com> wrote in message
news:Y5****************@newssvr27.news.prodigy.com ...
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

Nov 20 '05 #2
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.

Nov 20 '05 #3

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

Similar topics

2
by: Dena Leiter | last post by:
I want to send people to a new page using a redirect but I want a new window to open. Is this possible? I've tried this: <meta http-equiv="refresh"...
5
by: PM | last post by:
Has anyone found a way to open a file exclusively where it will fail if the file is already open, i have tried the following _FileStream = new FileStream(@"C:\Data.txt", FileMode.Open,...
2
by: Piyush | last post by:
Hi, I need to print stuff on the default printer on the click of a button without opening the print box opening up. Any pointers?
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
8
by: Vigneshwaran G via DotNetMonster.com | last post by:
Hi , I am in need of opening a new IE browser with an URL from my windows form, coded in vb.net. I tried with the following code. Dim psi As New ProcessStartInfo psi.FileName = "iexplore"...
1
by: kevcar40 | last post by:
hi is it possible to stop a form opening if the result of the query is null? eg select a company name from a combobox if the name is not in the table (ie the query returns null) can i stop...
11
by: aldrin | last post by:
I'm trying to run this code under windows xp sp2 using codeblocks v1.0 compiler with great difficulty.There is no problem with running this under KDevelop in linux. Any help would be greatly...
2
by: Craig | last post by:
Hi there, I'm trying to open colour BMPs using PIL and I'm getting the following errors. Opening a 16 colour BMP I get: Traceback (most recent call last): File "<pyshell#3>", line 1, in...
9
compman9902
by: compman9902 | last post by:
Hello, and thank toy for reading this post. Thus far, this website has helped me a lot, (I have finally finished my encryptor: "site removed by moderator", go to the downloads link) and I will...
34
by: Alexnb | last post by:
Gerhard Häring wrote: No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: Traceback (most recent call last): File...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.