DbHelper增加了两个Build方法分别构建IDbCommand与IDataParameter,同时增加了接受IDbCommand的接 口,这样做是为了在需要重复执行某个Command时不需要每次都重新构建Command浪费效率,现在可以用Build方法先构建出Command对 象,然后在循环中执行这个command,如下示例。
1
IDbHelper helper
=
new
SqliteHelper(
this
.connection);
2
3
IDbCommand insertCommand
=
helper.BuildCommand(
4
"
INSERT INTO Test VALUES(NULL, @num, @r_date, @data)
"
,
5
1
, DateTime.Now,
new
byte
[
0
]);
6
7
SQLiteConnection con
=
new
SQLiteConnection();
8
con.ConnectionString
=
this
.connection.ConnectionString;
9
10
con.Open();
11
12
IDbTransaction transaction
=
con.BeginTransaction(
13
IsolationLevel.ReadUncommitted);
14
insertCommand.Transaction
=
transaction;
15
16
try
{
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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16



17



18

19

20

21



22

23



24

25

26

关于DbHelper,请参看:
http://cavingdeep.cnblogs.com/category/37490.html
下载及Announcements