工作中数据层开始的时候我们是用NHIBERNATE的,后来发觉这个学习成本比较高,还有就是业务比较复杂的时候配置等各方面都比较麻烦,而且控制不好的话链接很容易爆满,后来我们该用直接用ADO.NET自己封装了一个操作类来满足这方面的需求,下面的代码是这个HELPER类的雏形。看起来都比较容易明白,所以注析就少了点。
这个类是按照NHIBERNATE的操作习惯进行封装的,该类把常用的基本操作和参数的设置以及事务等做了一次封装,因为时间关系先把这个类拷进来,具体的操作方法下次再给出来,
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
1
using System;
2
using System.Collections;
3
using System.Data;
4
using System.Text;
5
using System.Text.RegularExpressions;
6
using Oracle.DataAccess;
7
using Oracle.DataAccess.Client;
8
using System.Data.SqlClient;
9
using System.Reflection;
10![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
11
namespace KingCardService.Util
12![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
13
public class DataHelper : IDisposable
14![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
15![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
枚举#region 枚举
16![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
17
/// 数据库类型
18
/// </summary>
19
public enum MyDbType
20![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
21
ORACLE,
22
MSSQL
23
}
24
#endregion
25![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
26![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
字段#region 字段
27
private string _connectionString;
28
private IDbConnection _conn = null;
29
private IDbCommand _comm = null;
30
private IDbTransaction _transaction = null;
31
private CommandType _type = CommandType.Text;
32
private MyDbType _myDbType = MyDbType.MSSQL;
33
private ArrayList _pars = new ArrayList();
34
private ArrayList _trancomms = new ArrayList();
35
#endregion
36
public DataHelper(string connectionString):this(connectionString,MyDbType.ORACLE)
37![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
38
}
39
public DataHelper(string connectionString,MyDbType dbType)
40![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
41
_connectionString = connectionString;
42
_myDbType = dbType;
43
SetConnection();
44
}
45
private void SetConnection()
46![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
47
if (_conn == null)
48![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
49
if (_myDbType == MyDbType.ORACLE)
50![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
51
_conn = new OracleConnection(_connectionString);
52
}
53
else
54![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
55
_conn = new SqlConnection(_connectionString);
56
}
57
}
58
if (_conn.State == ConnectionState.Closed)
59![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
60
_conn.Open();
61
}
62
}
63![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
属性#region 属性
64![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
65
/// 数据库类型
66
/// 默认为ORACLE
67
/// 数据库
68
/// </summary>
69
public MyDbType DBType
70![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
71![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _myDbType; }
72![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ _myDbType = value; }
73
}
74![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
75![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
76
/// 获取数据库连接
77
/// </summary>
78
public IDbConnection Connection
79![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
80![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{
81
return _conn;
82
}
83
}
84![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
85
/// 事务
86
/// </summary>
87
public IDbTransaction Transaction
88![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
89![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _transaction; }
90
}
91
#endregion
92![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
93![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
事务处理#region 事务处理
94![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
95
/// 事务开始
96
/// </summary>
97
public void BeginTransaction()
98![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
99
if (_conn != null)
100![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
101
if (_conn.State == ConnectionState.Closed)
102
_conn.Open();
103
_transaction = _conn.BeginTransaction();
104
}
105
else
106![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
107
throw new Exception("未设置连接!");
108
}
109
}
110![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
111![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
112
/// 事务提交
113
/// </summary>
114
public void CommitTransaction()
115![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
116
_transaction.Commit();
117
_trancomms.Clear();
118
}
119![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
120![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
121
/// 事务回滚
122
/// </summary>
123
public void RollbackTransaction()
124![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
125
_transaction.Rollback();
126
_trancomms.Clear();
127
}
128![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
129
/// IDbCommand 对象的克隆
130
/// </summary>
131
/// <param name="comm"></param>
132
/// <returns></returns>
133
private IDbCommand DeepClone(IDbCommand comm)
134![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
135
if (comm != null)
136![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
137
IDbCommand command = comm.Connection.CreateCommand();
138
command.CommandText = comm.CommandText;
139
command.CommandTimeout = comm.CommandTimeout;
140
command.CommandType = comm.CommandType;
141
foreach (IDataParameter p in comm.Parameters)
142![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
143
IDataParameter p2 = command.CreateParameter();
p2.ParameterName = p.ParameterName;
p2.DbType = p.DbType;
p2.Value = p.Value;
command.Parameters.Add(p2);
144
}
145
return command;
146
}
147
else
148![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
149
return null;
150
}
151
}
152
#endregion
153![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
154![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
创建查询#region 创建查询
155![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
156
/// CreateQuery(string sql)
157
/// </summary>
158
/// <param name="sql">string sql</param>
159
/// <returns>DataHelper</returns>
160
public DataHelper CreateQuery(string sql)
161![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
162
if (_conn == null)
163
throw new Exception("请先设置数据库连接!");
164
_comm = _conn.CreateCommand();
165
_comm.CommandText = sql;
166
if(_conn.State == ConnectionState.Closed)
167
_conn.Open();
168
return this;
169
}
170![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
171![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
172
/// CreateQuery(IDbConnection conn, string sql, CommandType commandType)
173
/// </summary>
174
/// <param name="conn">IDbConnection conn</param>
175
/// <param name="sql">string sql</param>
176
/// <param name="commandType">CommandType commandType</param>
177
/// <returns>DataHelper</returns>
178
public DataHelper CreateQuery(string sql, CommandType commandType)
179![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
180
_type = commandType;
181
return CreateQuery(sql);
182
}
183
#endregion
184![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
185![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
执行查询#region 执行查询
186![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
187
/// 执行事务操作查询
188
/// </summary>
189
/// <returns>int val</returns>
190
public int ExecuteTransactionNoneQuery()
191![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
192
if (_transaction != null)
193![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
194
AddParameterToCommand();
195
IDbCommand comm = DeepClone(_comm);
196
_trancomms.Add(comm);
197
_comm.Dispose();
198
_comm = null;
199
comm.Transaction = _transaction;
200
return comm.ExecuteNonQuery();
201
}
202
else
203![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
204
throw new Exception("事务未打开!");
205
}
206
}
207![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
208![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
209
/// ExecuteNonQuery()
210
/// Exceptions:
211
/// System.InvalidOperationException
212
/// </summary>
213
/// <returns>int</returns>
214
public int ExecuteNonQuery()
215![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
216
AddParameterToCommand();
217
try
218![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
219
int result = _comm.ExecuteNonQuery();
220
return result;
221
}
222
catch (InvalidOperationException ex)
223![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
224
if (_conn != null && _conn.State == ConnectionState.Open)
225
_conn.Close();
226
throw ex;
227
}
228
catch (Exception ex)
229![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
230
if (_conn != null && _conn.State == ConnectionState.Open)
231
_conn.Close();
232
throw ex;
233
}
234
}
235![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
236![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
237
/// ExecuteScalar()
238
/// </summary>
239
/// <returns>object</returns>
240
public object ExecuteScalar()
241![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
242
AddParameterToCommand();
243
try
244![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
245
object obj = _comm.ExecuteScalar();
246
return obj;
247
}
248
catch (Exception ex)
249![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
250
if(_conn.State == ConnectionState.Open)
251
_conn.Close();
252
throw ex;
253
}
254
}
255![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
256![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
257
/// ExecuteReader()
258
/// </summary>
259
/// <returns>IDataReader</returns>
260
public IDataReader ExecuteReader()
261![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
262
AddParameterToCommand();
263
try
264![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
265
return _comm.ExecuteReader();
266
}
267
catch (Exception ex)
268![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
269
if (_conn != null && _conn.State == ConnectionState.Open)
270
_conn.Close();
271
throw ex;
272
}
273
}
274![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
275![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
276
/// ExecuteReader(CommandBehavior commandBehavior)
277
/// </summary>
278
/// <returns>IDataReader</returns>
279
public IDataReader ExecuteReader(CommandBehavior commandBehavior)
280![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
281
AddParameterToCommand();
282
try
283![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
284
return _comm.ExecuteReader(commandBehavior);
285
}
286
catch (Exception ex)
287![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
288
if (_conn != null && _conn.State == ConnectionState.Open)
289
_conn.Close();
290
throw ex;
291
}
292
}
293![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
294
/// ExecuteDataSet(MyDbType myDbType)
295
/// </summary>
296
/// <returns>DataSet</returns>
297
public DataSet ExecuteDataSet()
298![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
299
AddParameterToCommand();
300
if (_conn != null && _conn.State == ConnectionState.Open)
301
_conn.Close();
302
DataSet ds = new DataSet();
303
switch (_myDbType)
304![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
305
case MyDbType.ORACLE:
306
using(OracleDataAdapter adapter = new OracleDataAdapter((OracleCommand)_comm))
307![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
308
adapter.Fill(ds);
309
}
310
break;
311
case MyDbType.MSSQL:
312
using(SqlDataAdapter adapter = new SqlDataAdapter((SqlCommand)_comm))
313![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
314
adapter.Fill(ds);
315
}
316
break;
317
}
318
return ds;
319
}
320![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
321![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
322
/// ExecuteDataSet(int startRecord, int maxRecords, string srcTable)
323
/// </summary>
324
/// <param name="startRecord">int startRecord</param>
325
/// <param name="maxRecords">int maxRecords</param>
326
/// <param name="srcTable">string srcTable</param>
327
/// <returns>DataSet</returns>
328
public DataSet ExecuteDataSet(int startRecord, int maxRecords, string srcTable)
329![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
330
AddParameterToCommand();
331
if (_conn != null && _conn.State == ConnectionState.Open)
332
_conn.Close();
333
DataSet ds = new DataSet();
334
switch (_myDbType)
335![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
336
case MyDbType.ORACLE:
337
using (OracleDataAdapter adapter = new OracleDataAdapter((OracleCommand)_comm))
338![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
339
adapter.Fill(ds, startRecord, maxRecords, srcTable);
340
}
341
break;
342
case MyDbType.MSSQL:
343
using (SqlDataAdapter adapter = new SqlDataAdapter((SqlCommand)_comm))
344![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
345
adapter.Fill(ds, startRecord, maxRecords, srcTable);
346
}
347
break;
348
}
349
return ds;
350
}
351![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
352
#endregion
353![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
354![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
设置参数#region 设置参数
355![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
356
/// 将设置好的参数加到Command中去
357
/// </summary>
358
private void AddParameterToCommand()
359![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
360
_comm.Parameters.Clear();
361
if(_type == CommandType.StoredProcedure)
362![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
363
foreach(IDataParameter p in _pars)
364![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
365
_comm.Parameters.Add(p);
366
}
367
}
368
else
369![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
370
string sql = _comm.CommandText;
371
string spliter = _myDbType == MyDbType.MSSQL ? "@" : ":";
372
string pattern = string.Format(@"{0}\w+", spliter);
373
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern, RegexOptions.IgnoreCase);
374
MatchCollection col = reg.Matches(sql);
375
foreach(Match item in col)
376![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
377
string val = item.Value.ToLower();
378
foreach(IDataParameter p in _pars)
379![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
380
if(p.ParameterName.ToLower() == val && !_comm.Parameters.Contains(val))
381![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
382
_comm.Parameters.Add(p);
383
break;
384
}
385
}
386
}
387
}
388
_pars.Clear();
389
}
390![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
391![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
392
/// 设置参数
393
/// </summary>
394
/// <param name="name"></param>
395
/// <param name="dbType"></param>
396
/// <param name="value"></param>
397
/// <returns></returns>
398
private IDataParameter AddParameter(string name, DbType dbType, object value)
399![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
400
if (_comm != null)
401![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
402
IDataParameter p = _comm.CreateParameter();
403
p.ParameterName = _myDbType.Equals(MyDbType.MSSQL) ? string.Format("@{0}", name) : string.Format(":{0}", name);
404
p.DbType = dbType;
405
p.Value = value;
406
_pars.Add(p);
407
return p;
408
}
409
else
410![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
411
throw new Exception("IDbCommand对象为空!");
412
}
413
}
414![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
415![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
416
/// 设置参数
417
/// </summary>
418
/// <param name="name"></param>
419
/// <param name="dbType"></param>
420
/// <param name="value"></param>
421
/// <returns></returns>
422
private IDataParameter AddParameter(string name, DbType dbType, object value, ParameterDirection parameterDirection)
423![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
424
IDataParameter p = AddParameter(name, dbType, value);
425
if(_type == CommandType.StoredProcedure)
426![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
427
p.Direction = parameterDirection;
428
}
429
return p;
430
}
431![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
432![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
433
/// SetString(string name, string val)
434
/// </summary>
435
/// <param name="name">string name</param>
436
/// <param name="val">string val</param>
437
/// <returns>DataHelper</returns>
438
public DataHelper SetString(string name, string val)
439![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
440
AddParameter(name, DbType.String, (val == null ? string.Empty : val));
441
return this;
442
}
443![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
444![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
445
/// SetString(string name, string val, ParameterDirection parameterDirection)
446
/// </summary>
447
/// <param name="name">string name</param>
448
/// <param name="val">string val</param>
449
/// <param name="parameterDirection">ParameterDirection parameterDirection</param>
450
/// <returns>DataHelper</returns>
451
public DataHelper SetString(string name, string val, ParameterDirection parameterDirection)
452![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
453
AddParameter(name, DbType.String, val, parameterDirection);
454
return this;
455
}
456![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
457
public DataHelper SetDouble(string name, double val)
458![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
459
AddParameter(name, DbType.Double, val);
460
return this;
461
}
462![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
463
public DataHelper SetDouble(string name, double val, ParameterDirection parameterDirection)
464![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
465
AddParameter(name, DbType.Double, parameterDirection);
466
return this;
467
}
468![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
469
public DataHelper SetDecimal(string name, decimal val)
470![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
471
AddParameter(name, DbType.Decimal, val);
472
return this;
473
}
474![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
475
public DataHelper SetDecimal(string name, decimal val, ParameterDirection parameterDirection)
476![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
477
AddParameter(name, DbType.Decimal, val, parameterDirection);
478
return this;
479
}
480![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
481![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
482
/// SetInt32(string name, Int32 val)
483
/// </summary>
484
/// <param name="name">string name</param>
485
/// <param name="val">Int32 val</param>
486
/// <returns>DataHelper</returns>
487
public DataHelper SetInt32(string name, Int32 val)
488![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
489
AddParameter(name, DbType.Int32, val);
490
return this;
491
}
492![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
493![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
494
/// SetInt32(string name, Int32 val, ParameterDirection parameterDirection)
495
/// </summary>
496
/// <param name="name">string name</param>
497
/// <param name="val">Int32 va</param>
498
/// <param name="parameterDirection">ParameterDirection parameterDirection</param>
499
/// <returns>DataHelper</returns>
500
public DataHelper SetInt32(string name, Int32 val, ParameterDirection parameterDirection)
501![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
502
AddParameter(name, DbType.Int32, val, parameterDirection);
503
return this;
504
}
505![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
506![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
507
/// SetInt16(string name, Int16 val)
508
/// </summary>
509
/// <param name="name">string name</param>
510
/// <param name="val">Int16 val</param>
511
/// <returns>DataHelper</returns>
512
public DataHelper SetInt16(string name, Int16 val)
513![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
514
AddParameter(name, DbType.Int16, val);
515
return this;
516
}
517![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
518![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
519
/// SetInt16(string name, Int16 val, ParameterDirection parameterDirection)
520
/// </summary>
521
/// <param name="name">string name</param>
522
/// <param name="val">Int16 val</param>
523
/// <param name="parameterDirection">ParameterDirection parameterDirection</param>
524
/// <returns>DataHelper</returns>
525
public DataHelper SetInt16(string name, Int16 val, ParameterDirection parameterDirection)
526![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
527
AddParameter(name, DbType.Int16, val, parameterDirection);
528
return this;
529
}
530![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
531![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
532
/// SetDate(string name, DateTime val)
533
/// </summary>
534
/// <param name="name">string name</param>
535
/// <param name="val">DateTime val</param>
536
/// <returns>DataHelper</returns>
537
public DataHelper SetDate(string name, DateTime val)
538![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
539
AddParameter(name, DbType.Date, val);
540
return this;
541
}
542![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
543![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
544
/// SetDate(string name, DateTime val, ParameterDirection parameterDirection)
545
/// </summary>
546
/// <param name="name">string name</param>
547
/// <param name="val">DateTime val</param>
548
/// <param name="parameterDirection">ParameterDirection parameterDirection</param>
549
/// <returns>DataHelper</returns>
550
public DataHelper SetDate(string name, DateTime val, ParameterDirection parameterDirection)
551![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
552
AddParameter(name, DbType.Date, val, parameterDirection);
553
return this;
554
}
555![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
556![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
557
/// SetDateTime(string name, DateTime val)
558
/// </summary>
559
/// <param name="name">string name</param>
560
/// <param name="val">DateTime val</param>
561
/// <returns>DataHelper</returns>
562
public DataHelper SetDateTime(string name, DateTime val)
563![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
564
AddParameter(name, DbType.DateTime, val);
565
return this;
566
}
567![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
568![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
569
/// SetDateTime(string name, DateTime val, ParameterDirection parameterDirection)
570
/// </summary>
571
/// <param name="name">string name</param>
572
/// <param name="val">DateTime val</param>
573
/// <param name="parameterDirection">ParameterDirection parameterDirection</param>
574
/// <returns>DataHelper</returns>
575
public DataHelper SetDateTime(string name, DateTime val, ParameterDirection parameterDirection)
576![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
577
AddParameter(name, DbType.DateTime, val, parameterDirection);
578
return this;
579
}
580![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
581![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
582
/// SetEnum(string name, Enum val)
583
/// </summary>
584
/// <param name="name">string name</param>
585
/// <param name="val">Enum val</param>
586
/// <returns>DataHelper</returns>
587
public DataHelper SetEnum(string name, Enum val)
588![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
589
AddParameter(name, DbType.Int32, val.GetHashCode());
590
return this;
591
}
592![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
593![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
594
/// SetEnum(string name, Enum val, ParameterDirection parameterDirection)
595
/// </summary>
596
/// <param name="name">string name</param>
597
/// <param name="val">Enum val</param>
598
/// <param name="parameterDirection">ParameterDirection parameterDirection</param>
599
/// <returns>DataHelper</returns>
600
public DataHelper SetEnum(string name, Enum val, ParameterDirection parameterDirection)
601![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
602
AddParameter(name, DbType.Int32, val.GetHashCode(), parameterDirection);
603
return this;
604
}
605![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
606![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
607
/// SetEnum(string name, bool val)
608
/// </summary>
609
/// <param name="name">string name</param>
610
/// <param name="val">bool val</param>
611
/// <returns>DataHelper</returns>
612
public DataHelper SetBoolean(string name, bool val)
613![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
614
AddParameter(name, DbType.Byte, (val ? 1 : 0));
615
return this;
616
}
617![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
618![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
619
/// SetEnum(string name, bool val, ParameterDirection parameterDirection)
620
/// </summary>
621
/// <param name="name">string name</param>
622
/// <param name="val">bool val</param>
623
/// <param name="parameterDirection">ParameterDirection parameterDirection</param>
624
/// <returns>DataHelper</returns>
625
public DataHelper SetBoolean(string name, bool val, ParameterDirection parameterDirection)
626![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
627
AddParameter(name, DbType.Byte, (val ? 1 : 0), parameterDirection);
628
return this;
629
}
630
#endregion
631![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
632![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedSubBlock.gif)
IDisposable 成员#region IDisposable 成员
633![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
634
public void Dispose()
635![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
636
if(_comm != null)
637
_comm.Dispose();
638
if (_trancomms != null)
639![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
640
for (int i = 0; i < _trancomms.Count; i++)
641![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
642
if((IDbCommand)_trancomms[i] != null)
643
((IDbCommand)_trancomms[i]).Dispose();
644
}
645
}
646![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
647
if(_conn != null)
648
_conn.Dispose();
649
}
650![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
651
#endregion
652
}
653
}
654![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
655![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)