Release of DbHelper 1.2.1

DbHelper增加了两个Build方法分别构建IDbCommand与IDataParameter,同时增加了接受IDbCommand的接 口,这样做是为了在需要重复执行某个Command时不需要每次都重新构建Command浪费效率,现在可以用Build方法先构建出Command对 象,然后在循环中执行这个command,如下示例。

 1IDbHelper helper = new SqliteHelper(this.connection);
 2
 3IDbCommand insertCommand = helper.BuildCommand(
 4   "INSERT INTO Test VALUES(NULL, @num, @r_date, @data)",
 5   1, DateTime.Now, new byte[0]);
 6
 7SQLiteConnection con = new SQLiteConnection();
 8con.ConnectionString = this.connection.ConnectionString;
 9
10con.Open();
11
12IDbTransaction transaction = con.BeginTransaction(
13   IsolationLevel.ReadUncommitted);
14insertCommand.Transaction = transaction;
15
16try {
17   for (int i = 0; i < 100; i++{
18      helper.ExecuteCommand(insertCommand, i + 1, DateTime.Now, null);
19   }

20   transaction.Commit();
21}
 catch {
22   transaction.Rollback();
23}
 finally {
24   con.Close();
25}

26

关于DbHelper,请参看:

http://cavingdeep.cnblogs.com/category/37490.html

下载及Announcements

http://dbhelper.tigris.org

posted @ 2005-11-03 15:42  Cavingdeep  阅读(2527)  评论(4编辑  收藏  举报