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 976693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:47:18+00:00 2026-05-16T03:47:18+00:00

I try updating my database after updating the dataset, but evenafter calling the data

  • 0

I try updating my database after updating the dataset, but evenafter calling the data adapter’s update function the underlying database doesn’t change. I used SqlCommandBuilder and it still wouldn’t update. Once I have the GUI open I can submit and search for values in my dataset but once I close it then re run it, all the changes are gone. Help?

    Code:

        //in my form load event
        con = new System.Data.SqlClient.SqlConnection();
        ds1 = new DataSet();
        ds2 = new DataSet();

        con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database1.mdf;Integrated Security=True;User Instance=True";

        con.Open();
        MessageBox.Show("Database Open.");

        string sql = "SELECT * From tblPurchases";
        da = new System.Data.SqlClient.SqlDataAdapter(sql, con);

        string cust = "SELECT * From tblCustomers";
        da2 = new System.Data.SqlClient.SqlDataAdapter(cust, con);

        da.Fill(ds1, "Purchases");
        numOfRecords = ds1.Tables["Purchases"].Rows.Count;

        da2.Fill(ds2, "Customers");
        numOfCustomers = ds2.Tables["Customers"].Rows.Count;

        con.Close();
        MessageBox.Show("Database Closed.");

    Code:
            //in my submit button click event

            System.Data.SqlClient.SqlCommandBuilder cb;
            cb = new System.Data.SqlClient.SqlCommandBuilder(da);

            System.Data.SqlClient.SqlCommandBuilder cb2;
            cb2 = new System.Data.SqlClient.SqlCommandBuilder(da2);

            DataRow dRow = ds1.Tables["Purchases"].NewRow();
            DataRow dRow2 = ds2.Tables["Customers"].NewRow();

            //dRow updating happens here

            ds1.Tables["Purchases"].Rows.Add(dRow);
            ds2.Tables["Customers"].Rows.Add(dRow2);

            da.Update(ds1, "Purchases");
            da2.Update(ds2, "Customers");

That’s it. There are no error messages, it’s just that even with that, the underlying database doesn’t update and the updates only go as far as the dataset.

  • 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-05-16T03:47:18+00:00Added an answer on May 16, 2026 at 3:47 am

    The SqlDataAdapter.Update() method returns an integer with the number of rows successfully updated. Consider loading that value into a variable to determine if any rows were reported as updated.

    The SqlCommandBuilder likely needs its .GetUpdateCommand() method called. GetUpdateCommand gets the automatically generated SqlCommand object required to perform updates on the database.

    cb.GetUpdateCommand();
    cb2.GetUpdateCommand();
    
    da.Update(ds1, "Purchases");
    da2.Update(ds2, "Customers");
    

    Consider running SQL Server Profiler against your server to determine the TSQL statements that are being generated by the SqlCommand. This will be extremely helpful in determining if the database and statements are as you expect.

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

Sidebar

Related Questions

hey my problem is when i try to update my database it goes through
I am having trouble updating my Database from my code using a DataSet. I'm
I'm updating a C# (.NET 3.5) application to interact with an Access database, but
I try to construct 3-tier application. In DAL I get data from database (
I want to update data from my database using java. I have established my
try: html = urlopen('http://glbse.com/api/asset/' + asset.name) except: print 'error while updating the price of
I'm having an issue with updating the database. The app shows the updated value,
I'm having an issue when I try to update a task model to the
I am having problem with saving the changes to database. I am updating the
I am in the process of updating some tables in my database and I

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.