Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


multiple data sets

Posted on 2005-04-21
Medium Priority
Last Modified: 2010-04-23
Another one for you...
As i understand there are four main objects needed to connect to a DB

which of these can be reused across all queries and resulting datasets and which do i need to create for each separate SQL query

I had assumed that i only needed to do the connection once -but it only works with multiple connections... so does this mean that for every connection i make to the DB i need to go through setting up and populating each of these objects? isn't that really inefficient? it certainly seems it from the amount of code i am going to have to generate...

any tips or comments - am i going about this completely the wrong way?

Question by:lz7cjc
  • 2
  • 2
LVL 25

Accepted Solution

RonaldBiemans earned 200 total points
ID: 13832473
you need just one connection per database.
if you have multiple tables you want to update, create a dataadapter for each table.
if you don't want to update the table you could reuse the same dataadapter
the same goes for commands.
only one dataset is usually needed. the data inside the dataset are updated by the indivual adapters.

if you want to return just 1 value from a table, use the executescalar command
if you want to execute a query than doesn't return anything use executenonquery,

there is also the datareader

use this if the result doesn't need to be updated and you just want to loop through a set of variables


Author Comment

ID: 13832506
thanks Ronald... so why, when i reused the same DB connection, did i get an error?

would it be possible to explain a little more simply, how i can reuse a dataadapter on the same page... surely if i need to reference the data adapter to display one set of records it is in use and can't be used for another purpose... i.e aren't the commands executed in a linear fashion?

perhaps some example code of how i would connect once to the database to access 2 different datasets and then display the results, would help with my confusion? (lets forget about update etc for the moment and assume i am just displaying... i can ask a separate question on that later if i need to)

LVL 25

Expert Comment

ID: 13832541
Is this for web or windows ?

Author Comment

ID: 13832788
it is for web... all these questions relate to web

i am going to award the points on this since as it seems to have converged with my other question... count it as a downpayment!

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question