multiple data sets

Posted on 2005-04-21
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
    LVL 25

    Accepted Solution

    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

    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

    Is this for web or windows ?

    Author Comment

    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!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now