troubleshooting Question

Batch update in C#

Avatar of tia_kamakshi
tia_kamakshiFlag for United Arab Emirates asked on
5 Comments1 Solution1991 ViewsLast Modified:

I am working on using C#

I wanted to do Batch insert from my stored proc

I wrote below code

But to execute batch command I need DataTable, DataSet etc

Cannot I do this using my object as using my below code

Please help me doing batch update

Many Thanks
public void BatchUpdate(List<TripDetailValuesBO> tripDetailValuesList)
    int batchSize = 20;
    DbConnection dbConn = new DbConnection();
    SqlConnection connection = dbConn.Connection();

    SqlDataAdapter adapter = new SqlDataAdapter();

    foreach (TripDetailValuesBO tripDetailValuesBO in tripDetailValuesList)
	adapter.UpdateCommand = new SqlCommand(
	    "EXEC insertTripData @tripID, @questionID, @answer", connection);
	   SqlDbType.Int, tripDetailValuesBO.tripID);
	   SqlDbType.Int, tripDetailValuesBO.questionID);
	   SqlDbType.VarChar, 8000, tripDetailValuesBO.tripdata_question_answer);
	adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;

    adapter.UpdateBatchSize = batchSize;
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros