Hi there,

The program in hand must retrieve a bunch of data from an SQL Database (currently stored in a DataTable), fiddle around with the data, and then upload the changed data to the same SQL database.

Everything works fine at the mo apart from the final bit, uploading to the database. This is my current effort at uploading the data:

foreach (DataRow row in statementResult.Rows)
                {
                    SQLDataAdapter.Update(row);
                {

The DataTable (statementResult) is created as follows:

DataTable statementResult = new DataTable();

SQLDataAdapter.Fill(statementResult);

So basically I am looking for a few tips to update the database with the new DataTable.

Any help is appreciated,

Cheers.

Since you are filling statementResult, and updating rows in statementResult and then you are using for each row loop for the same statementResult, why don't you update the datatable?

SQLDataAdapter.Update(statementResult)

Since you are filling statementResult, and updating rows in statementResult and then you are using for each row loop for the same statementResult, why don't you update the datatable?

SQLDataAdapter.Update(statementResult)

Thanks for the advice mate, got it working now :icon_smile:

i hAVE WROTE THIS CODE TO CAN UPDATE MY DATABASE:

        OleDbDataAdapter adp = new OleDbDataAdapter("SELECT * FROM " + dtName, conn);

        try
        {
            OleDbCommandBuilder mycmdbuilder = new OleDbCommandBuilder(adp);
            adp.Fill(dt);
            mycmdbuilder.GetUpdateCommand();
            mycmdbuilder.GetInsertCommand();
            mycmdbuilder.GetDeleteCommand();
            adp.Update(dt);


        }

AND I HAVE GOT THIS ERROR MESSAGE:
אין תמיכה ביצירת SQL דינאמי עבור UpdateCommand כנגד SelectCommand שאינה מחזירה כל מידע אודות עמודת מפתח.
CAN YOU HELP ME?? I WOULD THANK YOU!!!

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.