Note that there are some explanatory texts on larger screens.

plurals
  1. POBulk Update in C#
    primarykey
    data
    text
    <p>For inserting a huge amount of data in a database, I used to collect all the inserting information into a list and convert this list into a <code>DataTable</code>. I then insert that list to a database via <code>SqlBulkCopy</code>.</p> <p>Where I send my generated list <br><code>LiMyList</code><br> which contain information of all bulk data which I want to insert to database<br> and pass it to my bulk insertion operation </p> <pre><code>InsertData(LiMyList, "MyTable"); </code></pre> <p>Where <code>InsertData</code> is</p> <pre><code> public static void InsertData&lt;T&gt;(List&lt;T&gt; list,string TableName) { DataTable dt = new DataTable("MyTable"); clsBulkOperation blk = new clsBulkOperation(); dt = ConvertToDataTable(list); ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); using (SqlBulkCopy bulkcopy = new SqlBulkCopy(ConfigurationManager.ConnectionStrings["SchoolSoulDataEntitiesForReport"].ConnectionString)) { bulkcopy.BulkCopyTimeout = 660; bulkcopy.DestinationTableName = TableName; bulkcopy.WriteToServer(dt); } } public static DataTable ConvertToDataTable&lt;T&gt;(IList&lt;T&gt; data) { PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T)); DataTable table = new DataTable(); foreach (PropertyDescriptor prop in properties) table.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType); foreach (T item in data) { DataRow row = table.NewRow(); foreach (PropertyDescriptor prop in properties) row[prop.Name] = prop.GetValue(item) ?? DBNull.Value; table.Rows.Add(row); } return table; } </code></pre> <p>Now I want to do an update operation, is there any way as for inserting data is done by <code>SqlBulkCopy</code> for Updating data to DataBase From C#.Net<br></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload