Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello Guys !

My Scenario Is

i am uploading ExcelSheet Which Contain id and Name in that excel sheet.

then that contain convert into table on server side using reading excelsheet.

now i want to update a status column against each and every row present in that table to sql server.


now i am using following code :


C#
foreach (DataRow row in dt.Rows)
                 {
                     Database database = DatabaseFactory.CreateDatabase(DALConstants.ConstantsBase.MIS);
                     string sqlcommand = "[PRDMIS_ExcelDeletion]";
                     DbCommand databasecommand =
                     database.AddInParameter(databasecommand, "ClientCode", DbType.String, row["id "].ToString());
                     database.AddInParameter(databasecommand, "Name", DbType.String, row["Name"].ToString());

                     int i = database.ExecuteNonQuery(databasecommand);
                 }



but it will hit server every time.
that i dont want it?


therefore

Is there any solution for that.

thanks
@ChetanV@
Posted

(1) Your code will connect with database each time, for inserting record. This is not recommended way. You should avoid it.
(2) You can go with BulkCopy mechanism. Here are some good link.

Link 1[^]

Link 2[^]
 
Share this answer
 
Comments
Wendelius 3-Feb-12 16:22pm    
Exactly, my 5.
use bcp to set the excel file as a table in your database. Create a stored procedure that handles the updates. Based on the where clause it can update all rows in 1 call
 
Share this answer
 
Comments
[no name] 3-Feb-12 23:21pm    
please Explain Briefly!
i Didnt get it.
Use typed dataset for bulk insert

Inserting relational data using DataSet and DataAdapter[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900