SQLite uses transaction update-by command

Source: Internet
Author: User
Tags sqlite

 public void Savetodb (DataTable dt) {/* Todo:sqlite does not provide a mechanism for bulk insertions and requires that all data be updated through a transaction * http://www             The. cnblogs.com/hbjohnsan/p/4169612.html * Eorr database is locked and cannot execute its own code.            */String CONNSTR = @ "Data source=e:\yqsqlite\yqsqlite\data\yq.db"; using (sqliteconnection conn = new Sqliteconnection (CONNSTR)) {Conn.                Open (); using (System.Data.SQLite.SQLiteTransaction trans = conn. BeginTransaction ()) {using (System.Data.SQLite.SQLiteCommand cmd = new Sqlitecommand (CO nn)) {cmd.                        Transaction = trans; try {foreach (DataRow dr in DT). Rows) {cmd. CommandText = @ "Insert or ignore into RssItem () VALUES (" +int32.parse (dr[0). ToString ()) + ", '" +dr[1]. ToString () +"', '" +dr[2. ToString () + "', '" + dr[3]. ToString () + "', '" + datetime.parse (dr[4). ToString ()) + "', '" +dr[5]. ToString () + "', '" +dr[6].                                ToString () + "')"; Cmd.                            ExecuteNonQuery ();                        } trans.commit (); } catch (Exception ex) {MessageBox.Show (ex.                            Message); Trans.                        Rollback (); }                    }                }            }                                                      }

  

SQLite uses transaction update-by command

Related Article

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.