Answered Questions

  • C# Data Table Multiple Rows

    You have multiple rows in C# data table and you have to save it in database using just one call, How will you do it?

    Star Read Best Answer

    Editorial / Best Answer

    LordAlex  

    • Member Since Nov-2011 | Nov 5th, 2011


    In a typical multiple-tier implementation, the steps for creating and refreshing a DataSet, and in turn, updating the original data are to: 1. Build and fill each DataTable in a DataSet with data from a data source using a DataAdapter. 2. Change the data in individual DataTable objects by adding, updating, or deleting DataRow objects. 3. Invoke the GetChanges method to create a second DataSet that features only the changes to the data. 4. Call the Update method of the DataAdapter, passing the second DataSet as an argument. 5. Invoke the Merge method to merge the changes from the second DataSet into the first. 6. Invoke the AcceptChanges on the DataSet. Alternatively, invoke RejectChanges to cancel the changes.

    Vasu

    • Apr 10th, 2015

    Yes

    indrajith

    • Jan 22nd, 2015

    We can use SqlBulkCopy class here for example

    Code
    1. SqlBulkCopy  bulkCopy=new SqlBulkCopy  (sqlconn);
    2.  bulkCopy.DestinationTableName = "dbtablename";
    3.  bulkCopy.WriteToServer(datatable);
    4.