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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:38:44+00:00 2026-05-23T22:38:44+00:00

Could somebody take a quick peek at my ado.net code? I am trying to

  • 0

Could somebody take a quick peek at my ado.net code? I am trying to update the row from a dataset, but it just isn’t working. I am missing some elemental piece of the code, and it is just eluding me. I have verified that the DataRow actually has the correct data in it, so the row itself is accurate.

Many thanks in advance.

 try
            {
                //basic ado.net objects
                SqlDataAdapter dbAdapter = null;
                DataSet returnDS2 = new DataSet();

                //a new sql connection
                SqlConnection myConn = new SqlConnection();
                myConn.ConnectionString = "Server=myserver.mydomain.com;"
                     + "Database=mydatabase;"
                     + "User ID=myuserid;"
                     + "Password=mypassword;"
                     + "Trusted_Connection=True;";

                //the sqlQuery
                string sqlQuery = "select * from AVLUpdateMessages WHERE ID = 21";

                //another ado.net object for the command
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = myConn;
                cmd.CommandText = sqlQuery;

                //open the connection, execute the SQL statement and then close the connection.
                myConn.Open();

                //instantiate and fill the sqldataadapter
                dbAdapter = new SqlDataAdapter(cmd);
                dbAdapter.Fill(returnDS2, @"AVLUpdateMessages");

                //loop through all of the rows; I have verified that the rows are correct and returns the correct data from the db
                for (int i = 0; i <= returnDS2.Tables[0].Rows.Count - 1; i++)
                {
                    DataRow row = returnDS2.Tables[0].Rows[i];
                    row.BeginEdit();
                    row["UpdatedText"] = @"This is a test...";
                    row.EndEdit();
                }

                //let's accept the changes
                dbAdapter.Update(returnDS2, "AVLUpdateMessages");
                returnDS2.AcceptChanges();

                myConn.Close();

            }  
  • 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-23T22:38:46+00:00Added an answer on May 23, 2026 at 10:38 pm

    You might be able to use SqlCommandBuilder to help out. After the Fill call, add the following statement. That will associate a command builder with the data adapter and (if there is a primary key available) it should generate the update statement for you. Note that there is some expense behind the command builder. It may not be much relative to everything else, but it does involve looking at schema information (to get primary key information, field names, field types, etc.) for the table and generating INSERT, DELETE, and UPDATE statements involving all fields in the table.

    SqlCommandBuilder cb = new SqlCommandBuilder(dbAdapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could somebody please take some time to show me a quick example on how
Could somebody please name a few. I could given time, but this is for
Could somebody point me to an example how to search for phrases with Lucene.net?
Could somebody please explain to me why does this code only print 42 instead
Ok, if somebody could take a look at this, I'd really appreciate it. I'm
could somebody please tell me why this code fails. url is nil after calling
Could somebody please do a rundown of how to programmatically encrypt a config-file in
Could somebody please point me in the right direction for learning how to do
Could somebody give me a brief overview of the differences between HTTP 1.0 and
Could somebody please explain to me what happens here? I am creating a binding

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.