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!!!

thanks. its good for me:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.