Search code examples
c#datatabletransactions

Is System.Data.DataTable in C# eligible for transactions?


I am just a beginner in C# and now I work with table data only in the form of System.Data.DataTable, that is in-memory data. From my work elsewhere I know that there is such thing as transactions. Right now I need something like that in my work with DataTable. I found a System.Transactions namespace in the Visual Studio help. But I cannot dig whether it is applicable to DataTable. Neither could I find the answer in Google. Everywhere they are talking about transactions in C# concerning database engines like MS SQL, Oracle, ADO etc. So here I am with my probably very easy question: is System.Data.DataTable in C# eligible for transactions? For example, can I begin a transaction, add some rows to my DataTable, and then rollback? If this is possible, could you please give a sample code


Solution

  • Many thanks everyone for your prompt answer. Your suggestion about AcceptChanges and RejectChanges turned out to be exactly what I needed. I am inserting rows in a set of tables with parent-child relations. If no data is found for a certain subject for inserting in the last child table, then nothing should be inserted in any table at all. And now I can achieve this, by issuing DataSet.AcceptChanges() before starting a new subject, and issuing AcceptChanges() or RejectChanges() respectively after processing the subject completely