Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8646673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:52:30+00:00 2026-06-12T12:52:30+00:00

I am trying to learn about how to work with databases in C# and

  • 0

I am trying to learn about how to work with databases in C# and I have gotten to a part in a tutorial when I have to work with DataSet , SqlDataAdapter and SqlCommandBuilder.This is the code I wrote in the example in the tutorial:

 public void InitData() {
        //instantiate the connection
        conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=\"D:\\Projects IDE\\Visual Studio\\Exercitii\\Console.app\\WindowsFormsApplication1\\WindowsFormsApplication1\\PlanetWrox.mdf\";Integrated Security=True;User Instance=True");

        //1.instantiate a new DataSet
        dsCustomers = new DataSet();

        //2.init SqlDataAdapter with select command and connection
        daCustomers = new SqlDataAdapter("SELECT Id ,Name, SortOrder FROM Genre", conn);

        // 3. fill in insert, update, and delete commands
        SqlCommandBuilder cmdBldr = new SqlCommandBuilder(daCustomers);

        // 4. fill the dataset
        daCustomers.Fill(dsCustomers, tableName);
    }

    public void btnUpdateClicked(object sender, EventArgs e) {
        // write changes back to DataBase
        daCustomers.Update(dsCustomers, tableName);

    }   

There are a couple of things I do not understand here:

The first thing I noticed is that I do not have to open and close the database.From what limited knoledge I have about databases I know that in order to acces the data you have to open a connection to it and after you are done you have to close it.This must happen somewhere behind the scene.Is that righT? If that is so witch method does that?

The second question is regarding the SqlDataAdapter and SqlCommandBuilder.I do not understand what does SqlCommandBuilder does here.Isen’t the SqlDataAdapter the one that is executing the sql query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:52:31+00:00Added an answer on June 12, 2026 at 12:52 pm

    The first thing I noticed is that I do not have to open and close the
    database.

    SqldataAdapter.Fill will open/close the connection for you.

    If the IDbConnection is closed before Fill is called, it is opened to
    retrieve data and then closed. If the connection is open before Fill
    is called, it remains open.

    The SqlCommandBuilder generates INSERT, UPDATE, or DELETE statements from the metadata of your provided select-statement. On this way you can call daCustomers.Update and all changes made to the DataSet will automatically be updated in the database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn about this feature of javascript I keep seeing in code,
Trying to learn about php's arrays today. I have a set of arrays like
I'm trying to learn about stack base overflow and write a simple code to
Sorry I am a noob, I am trying to learn about sqlite databases using
I'm trying to learn more about 'ajax' and so far have had the most
I have been trying to learn about resources and styles, I want to create
I'm trying to learn more about how systems really work underneath all the pretty
Possible Duplicate: How does a debugger work? I'm trying to learn more about debuggers.
I'm trying to learn more about how web and tcp work by implementing web
I was trying to learn more about bits, and I came across this example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.