Code for batch inserting Dataset data in a stored procedure with the UpdateDaset Method

Source: Internet
Author: User
Use the stored procedure with the UpdateDaset method to insert Dataset data in batches. If you are interested, do not miss it. I hope this article will provide you with knowledge points.

Use the stored procedure with the UpdateDaset method to insert Dataset data in batches. If you are interested, do not miss it. I hope this article will provide you with knowledge points.

The Code is as follows:
Public bool SaveSMSMessage (SMSBatch smsBatch, DataSet smsMessages)
{
// Using (TransactionScope ts = new TransactionScope (transactionscospontion. Suppress ))
//{
Foreach (DataRow row in smsMessages. Tables [0]. Rows)
Row. SetModified ();
SqlDatabase db = new SqlDatabase (this. ConsultantsConnString );
String sqlCmd = "EXEC cn. SMSSaveSMSMessage @ SMSBatchID, @ SMSTypeID, @ SubsidiaryID, @ ContactID, @ Message, @ PhoneNumber ";
Using (SqlCommand cmd = db. GetSqlStringCommand (sqlCmd) as SqlCommand)
{
Cmd. CommandTimeout = 600;
Cmd. Parameters. AddWithValue ("@ SMSBatchID", smsBatch. SMSBatchID );
Cmd. Parameters. AddWithValue ("@ SMSTypeID", smsBatch. SMSType. SMSTypeID );
Cmd. Parameters. AddWithValue ("@ SubsidiaryID", smsBatch. SMSType. SubsidiaryID );
Db. AddInParameter (cmd, "@ ContactID", DbType. Int64, "ContactID", DataRowVersion. Current );
Db. AddInParameter (cmd, "@ Message", DbType. String, "Message", DataRowVersion. Current );
If (smsMessages. Tables [0]. Columns. Contains ("PhoneNumber "))
{
Db. AddInParameter (cmd, "@ PhoneNumber", DbType. String, "PhoneNumber", DataRowVersion. Current );
}
Else
{
Db. AddInParameter (cmd, "@ PhoneNumber", DbType. String, DBNull. Value );
}
Int rowsEffected = db. UpdateDataSet (smsMessages, "SMSMessage", null, cmd, null, UpdateBehavior. Transactional );
SqlCmd = rowsEffected. ToString ();
}
// Ts. Complete ();
/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.