SqlParameter Transactional Bulk Data insertion

Source: Internet
Author: User

Yes, good. Batch transaction submission at the rear although it's a bit of a hassle, it won't be a problem.

1 SqlCommand cmd;2Helpsqlserver helps =Newhelpsqlserver ();3         //Defining SqlParameter Arrays4sqlparameter[] param =Newsqlparameter[4];5 6 7         protected voidPage_Load (Objectsender, EventArgs e)8         {9             varstrSQL ="";Ten              for(inti =0; I <4; i++) One             { AstrSQL + ="INSERT INTO Questions (PID) Values"; -strSQL + ="(@PID"+ i +");"; -  theParam[i] =NewSqlParameter ("@PID"+ i +"", sqldbtype.uniqueidentifier); -Param[i]. Value =Guid.NewGuid (); -  -             } +  -             using(SqlConnection conn =NewSqlConnection (helpsqlserver.connectionstring)) +             { Acmd =NewSqlCommand (strSQL, conn); at  -  - Conn. Open (); -SqlTransaction transaction =Conn. BeginTransaction (); -  -Cmd. Transaction =transaction; in                 foreach(SqlParameter parainchparam) -                 { to cmd. Parameters.Add (para); +                 } -  the                 Try *                 { $ cmd. ExecuteNonQuery ();Panax Notoginseng transaction.commit (); -                 } the                 Catch +                 { A transaction. Rollback (); the                 } +             } -  $}
View Code

SqlParameter Transactional Bulk Data insertion

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.