南骏 池
2024-12-11 c338b925c76530a4daedbe9aea5d1591b4faa583
1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
using System.Collections.Generic;
 
namespace DataexchangeServer
{
    using System;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Data;
    using System.Data.Sql;
    using System.Data.SqlClient;
    using System.Text.RegularExpressions;
 
    public class SQLHelper : ICloneable, IDisposable
    {
        private SqlConnection _connection4Tran;
        private readonly string _connectionString;
        private SqlTransaction _transaction;
        private readonly Queue<SqlTask> _transactionTaskList;
 
        public SQLHelper(string connectionString)
        {
            _transactionTaskList = new Queue<SqlTask>();
            this._connectionString = connectionString;
        }
 
        public SQLHelper(string server, string userID, string password, string database)
        {
            _transactionTaskList = new Queue<SqlTask>();
            if (database == string.Empty)
            {
                this._connectionString = "Data Source=" + server + ";User ID=" + userID + ";Password=" + password;
            }
            else
            {
                this._connectionString = "Data Source=" + server + ";User ID=" + userID + ";Password=" + password + ";Initial Catalog=" + database;
            }
        }
 
        public void BeginTransaction(IsolationLevel isolationLevel)
        {
            if ((this._transaction != null) || (this._connection4Tran != null))
            {
                throw new Exception("要开始一个新的事务,请先完成当前事务!");
            }
            this._connection4Tran = new SqlConnection(this._connectionString);
            this._connection4Tran.Open();
            this._transaction = this._connection4Tran.BeginTransaction(isolationLevel);
            _transactionTaskList.Clear();
        }
 
        public void CancelTransaction()
        {
            if (this._transaction != null)
            {
                this._transaction.Dispose();
            }
            if (this._connection4Tran != null)
            {
                this._connection4Tran.Close();
            }
            if (this._connection4Tran != null)
            {
                this._connection4Tran.Dispose();
            }
            this._transaction = null;
            this._connection4Tran = null;
        }
 
        public object Clone()
        {
            return new SQLHelper(this._connectionString);
        }
 
        public void CommitTransaction()
        {
            try
            {
                if (_transactionTaskList.Count > 0)
                {
                    foreach (SqlTask sqlTask in _transactionTaskList)
                    {
                        using (var command = new SqlCommand(sqlTask.Text, _connection4Tran))
                        {
                            command.CommandType = sqlTask.CommandType;
                            if (sqlTask.Parameters != null)
                            {
                                foreach (SqlParameter parameter in sqlTask.Parameters)
                                {
                                    command.Parameters.Add(parameter);
                                }
                            }
                            command.Transaction = _transaction;
                            command.ExecuteNonQuery();
                        }
                    }
                }
                this._transaction.Commit();
            }
            catch (Exception)
            {
                this._transaction.Rollback();
            }
            finally
            {
                if (this._transaction != null)
                {
                    this._transaction.Dispose();
                }
                if (this._connection4Tran != null)
                {
                    this._connection4Tran.Close();
                }
                if (this._connection4Tran != null)
                {
                    this._connection4Tran.Dispose();
                }
                this._transaction = null;
                this._connection4Tran = null;
            }
        }
 
        public DataSet ExecuteDataSet(string sql)
        {
            return this.ExecuteDataSet(sql, CommandType.Text, null);
        }
 
        public DataSet ExecuteDataSet(string sql, CommandType commandType)
        {
            return this.ExecuteDataSet(sql, commandType, null);
        }
 
        public DataSet ExecuteDataSet(string sql, CommandType commandType, SqlParameter[] parameters)
        {
            DataSet dataSet = new DataSet(Guid.NewGuid().ToString());
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = commandType;
                    if (parameters != null)
                    {
                        foreach (SqlParameter parameter in parameters)
                        {
                            command.Parameters.Add(parameter);
                        }
                    }
                    new SqlDataAdapter(command).Fill(dataSet);
                }
            }
            return dataSet;
        }
 
        public DataTable ExecuteDataTable(string sql)
        {
            return this.ExecuteDataTable(sql, CommandType.Text, null);
        }
 
        public DataTable ExecuteDataTable(string sql, CommandType commandType)
        {
            return this.ExecuteDataTable(sql, commandType, null);
        }
 
        public DataTable ExecuteDataTable(string sql, CommandType commandType, SqlParameter[] parameters)
        {
            DataTable dataTable = new DataTable(Guid.NewGuid().ToString());
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = commandType;
                    if (parameters != null)
                    {
                        foreach (SqlParameter parameter in parameters)
                        {
                            command.Parameters.Add(parameter);
                        }
                    }
                    new SqlDataAdapter(command).Fill(dataTable);
                }
            }
            return dataTable;
        }
 
        public int ExecuteNonQuery(string sql)
        {
            return this.ExecuteNonQuery(sql, CommandType.Text, null);
        }
 
        public int ExecuteNonQuery(string sql, CommandType commandType)
        {
            return this.ExecuteNonQuery(sql, commandType, null);
        }
 
        public int ExecuteNonQuery(string sql, CommandType commandType, SqlParameter[] parameters)
        {
            return this.ExecuteNonQuery(sql, commandType, parameters, false);
        }
 
        public int ExecuteNonQuery(string sql, CommandType commandType, SqlParameter[] parameters, bool joinTransaction)
        {
            int num;
            SqlCommand command;
            if (joinTransaction)
            {
                if ((this._transaction == null) || (this._connection4Tran == null))
                {
                    throw new Exception("事务未初始化!");
                }
               
                _transactionTaskList.Enqueue(new SqlTask(sql, commandType, parameters));
            }
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                using (command = new SqlCommand(sql, connection))
                {
                    command.CommandType = commandType;
                    if (parameters != null)
                    {
                        foreach (SqlParameter parameter in parameters)
                        {
                            command.Parameters.Add(parameter);
                        }
                    }
                    connection.Open();
                    num = command.ExecuteNonQuery();
                }
            }
            return num;
        }
 
        public SqlDataReader ExecuteReader(string sql)
        {
            return this.ExecuteReader(sql, CommandType.Text, null);
        }
 
        public SqlDataReader ExecuteReader(string sql, CommandType commandType)
        {
            return this.ExecuteReader(sql, commandType, null);
        }
 
        public SqlDataReader ExecuteReader(string sql, CommandType commandType, SqlParameter[] parameters)
        {
            SqlConnection connection = new SqlConnection(this._connectionString);
            SqlCommand command = new SqlCommand(sql, connection)
            {
                CommandType = commandType
            };
            if (parameters != null)
            {
                foreach (SqlParameter parameter in parameters)
                {
                    command.Parameters.Add(parameter);
                }
            }
            connection.Open();
            return command.ExecuteReader(CommandBehavior.CloseConnection);
        }
 
        public object ExecuteScalar(string sql)
        {
            return this.ExecuteScalar(sql, CommandType.Text, null);
        }
 
        public object ExecuteScalar(string sql, CommandType commandType)
        {
            return this.ExecuteScalar(sql, commandType, null);
        }
 
 
        public object ExecuteScalar(string sql, CommandType commandType, SqlParameter[] parameters)
        {
            object obj2;
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = commandType;
                    if (parameters != null)
                    {
                        foreach (SqlParameter parameter in parameters)
                        {
                            command.Parameters.Add(parameter);
                        }
                    }
                    connection.Open();
                    obj2 = command.ExecuteScalar();
                }
            }
            return obj2;
        }
 
        public DataTable GetDatabases()
        {
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                connection.Open();
                return connection.GetSchema("Databases");
            }
        }
 
        public static ArrayList GetServerList()
        {
            ArrayList list = new ArrayList();
            foreach (DataRow row in SqlDataSourceEnumerator.Instance.GetDataSources().Rows)
            {
                list.Add(row[0].ToString());
            }
            return list;
        }
 
        public DataTable GetTables()
        {
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                connection.Open();
                return connection.GetSchema("Tables");
            }
        }
 
        public bool SaveDataToDB(DataSet dataSet)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    foreach (DataTable table in dataSet.Tables)
                    {
                        using (SqlCommand command = new SqlCommand("SELECT * FROM " + table.TableName + " WHERE 1<1", connection))
                        {
                            SqlDataAdapter adapter = new SqlDataAdapter(command);
                            SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
                            adapter.UpdateBatchSize = 100;
                            DataTable tbchange = table.GetChanges();
                            if (tbchange != null)
                                adapter.Update(table.GetChanges());
                        }
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
 
        public bool SaveDataToDB(DataTable dataTable)
        {
            try
            {
                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    using (SqlCommand command = new SqlCommand("select top 0 * from " + dataTable.TableName, connection))
                    {
                        SqlDataAdapter adapter = new SqlDataAdapter(command);
 
                        SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
                        adapter.UpdateBatchSize = 100;
                        DataTable tbchange = dataTable.GetChanges();
                        if (tbchange != null)
                            adapter.Update(dataTable);
                    }
                }
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
 
 
        public bool SaveDataToDB(DataSet oldDataSet, DataSet newDataSet)
        {
            //bool flag;
            oldDataSet.Merge(newDataSet, false);
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                connection.Open();
                SqlTransaction transaction = connection.BeginTransaction();
                try
                {
                    foreach (DataTable table in oldDataSet.Tables)
                    {
                        using (SqlCommand command = new SqlCommand("SELECT * FROM " + table.TableName + " WHERE 1<1", connection, transaction))
                        {
                            SqlDataAdapter adapter = new SqlDataAdapter(command);
                            SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
                            adapter.UpdateBatchSize = 500;
                            adapter.Update(table);
                        }
                    }
                    transaction.Commit();
                    return true;
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }
                finally
                {
                    if (transaction != null)
                    {
                        transaction.Dispose();
                    }
                }
            }
            //return flag;
        }
 
        public bool SaveDataToDB(DataTable oldDataTable, DataTable newDataTable)
        {
            bool flag;
            oldDataTable.Merge(newDataTable, false);
            using (SqlConnection connection = new SqlConnection(this._connectionString))
            {
                using (SqlCommand command = new SqlCommand("SELECT * FROM " + oldDataTable.TableName + " WHERE 1<1", connection))
                {
                    SqlDataAdapter adapter = new SqlDataAdapter(command);
                    SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
                    adapter.UpdateBatchSize = 100;
                    adapter.Update(oldDataTable);
                    flag = true;
                }
            }
            return flag;
        }
 
        public bool TestConnection()
        {
            bool flag;
            try
            {
                using (SqlConnection connection = new SqlConnection(this._connectionString))
                {
                    connection.Open();
                    connection.Close();
                    flag = true;
                }
            }
            catch (Exception)
            {
                flag = false;
            }
            return flag;
        }
 
        #region IDisposable 成员
 
        public void Dispose()
        {
            _connection4Tran = null;
            _transaction = null;
        }
 
        #endregion
 
        private class SqlTask
        {
            public string Text { get; private set; }
            public CommandType CommandType { get; private set; }
            public SqlParameter[] Parameters { get; private set; }
 
            public SqlTask(string text, CommandType commandType, SqlParameter[] paras)
            {
                Text = text;
                CommandType = commandType;
                Parameters = paras;
            }
        }
 
        //public bool Save(DataTable Table, bool UpdateTableStatus, bool UseTransaction, bool ShowMsg)
        //{
        //    //如果不需要保存则退出。
        //    if (Table == null  )
        //        return true;
 
        //    SqlDataAdapter dataAdapter = new SqlDataAdapter();
 
        //        dataAdapter.UpdateCommand = GetUpdateCmd(Table);
        //        dataAdapter.InsertCommand = GetInsertCmd(Table);
        //        dataAdapter.DeleteCommand = GetDeleteCmd(Table);
 
 
        //    if (DBTransaction != null)
        //    {
        //        if (dataAdapter.SelectCommand != null) dataAdapter.SelectCommand.Transaction = DBTransaction;
        //        if (dataAdapter.DeleteCommand != null) dataAdapter.DeleteCommand.Transaction = DBTransaction;
        //        if (dataAdapter.InsertCommand != null) dataAdapter.InsertCommand.Transaction = DBTransaction;
        //        if (dataAdapter.UpdateCommand != null) dataAdapter.UpdateCommand.Transaction = DBTransaction;
        //    } 
 
        //    //更新数据
        //    try
        //    {
        //        //启动事务
        //        if (UseTransaction == true)
        //            StartTransaction();
 
        //        DataTable tb_changes = Table.GetChanges();
        //        if (tb_changes != null)
        //            dataAdapter.Update(tb_changes);
        //        else if (HandCreateCmd == true)
        //            dataAdapter.Update(Table);
        //        //提交事务
        //        if (UseTransaction == true)
        //            CommitTransaction();
 
        //        //修改表状态 如果前面的处理出错,那么这里也不会执行,Datatable将继续保留状态.
        //        if (UpdateTableStatus == true)
        //            Table.AcceptChanges();
 
        //        ExecuteExcetion = null;
        //    }
        //    catch (Exception e)
        //    {
        //        string errorMsg = "";
        //        //2627表示主键重复,才需要重取单号。
        //        if (e is SqlException)
        //        {
        //            SqlException sqlExcept = e as SqlException;
        //            SaveKeyExist = (sqlExcept.Number == 2627);
        //            if (sqlExcept.Number == 2627)
        //                errorMsg = "当前数据表已有此记录,请确认后再保存!";
        //            else
        //                errorMsg = ((SqlException)e).Message;
        //        }
 
        //        if (e is DBConcurrencyException)
        //        {
        //            DBConcurrencyException dbexception = (e as DBConcurrencyException);
        //            errorMsg = dbexception.Row.RowError;
        //            if (errorMsg.Contains("影响") == true && dbexception.Row.RowState == DataRowState.Deleted)
        //                errorMsg = "当前数据行已删除,请重新查询!";
        //            if (errorMsg.Contains("影响") == true && dbexception.Row.RowState == DataRowState.Modified)
        //                errorMsg = "当前数据行已修改,请重新查询!";
        //        }
 
        //        //
        //        ShowMsg = ShowMsg || ShowMsgWhenSaveChildTableOnError;
        //        ExecuteExcetion = e;
 
        //        //保存失败回滚事务
        //        if (UseTransaction == true)
        //            RollbackTransaction();
 
        //        errorMsg = (errorMsg == "") ? GetErrorMsg(e) : errorMsg;
        //        WriteLog(Format("保存{0}失败,错误信息如下:{1}", Table.TableName, errorMsg), ShowMsg);
        //        return false;
        //    }
        //    finally
        //    {
        //        Table.State = OptionState.Browse;
        //    }
 
        //    if (ShowMsg == true || MustSaveLog == true)
        //    {
        //        /* 关于ShowMsg参数的使用说明:
        //         * A方法:Save(bool UseTransaction, bool ShowMsg);
        //         * B方法:Save(DataTableExt Table,bool UpdateTableStatus, bool UseTransaction, bool ShowMsg);
        //         * 
        //         * A方法调用B方法时,是不需要提示"保存成功"的信息,所以A方法传的ShowMsg=false,但A希望在调用B方法出错时,
        //         * 提示错误信息"保存**失败..",所以原来B方法Catch中硬编码 ShowMsg=true;在执行改方法时,不管是否需要提示,系统都会提示信息(这有违背方法本意)。
        //         * 
        //         * 现在希望能利正确使用ShowMsg参数,所以引入了ShowMsgWhenSaveChildTableOnError属性(默认True)。
        //         * 当ShowMsgWhenSaveChildTableOnError等于True或ShowMsg等于True时,Catch中就会提示错误信息。
        //         *
        //         * 单据类BillClass保存时,由于特殊处理,希望过程中不提示错误信息,所以在保存时Save(UseTransaction, ShowMsg==false)和设置ShowMsgWhenSaveChildTableOnError=false。                 
        //         */
        //        WriteLog(string.Format("保存{0}成功!", Table.TableName), ShowMsg);
        //    }
        //    return true;
        //}
 
        // <summary>
        // 得到更新命令
        // </summary>
        // <returns></returns>
        //public SqlCommand GetUpdateCmd(DataTable MyTable, SqlConnection DBConn)
        //{ 
        //    生成更新语句
        //    string strSQL = string.Format("Update {0} Set ", MyTable.TableName);
        //    foreach (DataColumn col in MyTable.Columns)
        //    { 
        //        strSQL = string.Format("{0} {1}=@{1},", strSQL, col.ColumnName);
        //    }
        //    strSQL = strSQL.Substring(0, strSQL.Length - 1);
 
        //    StringCollection KeyList = new StringCollection();
        //    KeyList.Add("taskid");
        //    根据主键设置Where条件
        //    string strWhere = "";
        //    foreach (string Key in KeyList)
        //    {
        //        strWhere = strWhere == "" ? string.Format("{0}=@{0}", Key) : string.Format("{0} and {1}=@{1}", strWhere, Key);
        //    }
 
        //    strSQL = string.Format("{0} where {1}", strSQL, strWhere);
        //    SqlCommand updateCmd = new SqlCommand(strSQL, DBConn);
 
        //    添加参数
        //    foreach (DataColumn col in MyTable.Columns)
        //    {
        //        排除不用保存字段。
        //        SqlDbType SQLType = DataTypeMap.CSTypeToSqlType(col.DataType.Name);
        //        int Size = (col.MaxLength > 0) ? col.MaxLength : 100;
        //        updateCmd.Parameters.Add("@" + col.ColumnName, SQLType, Size, col.ColumnName);
        //    }
 
        //    return updateCmd;
        //}
 
 
        ///// <summary>
        ///// 得到插入命令
        ///// </summary>
        ///// <returns></returns>
        //public SqlCommand GetInsertCmd(DataTable MyTable)
        //{
        //    //取得主键
        //    List<string> KeyList = new List<string>();
        //    KeyList.AddRange(MyTable.KeyField.Split(';'));
        //    if (KeyList.Count <= 0)
        //        return null;
 
        //    //取得不需要更新的字段列表
        //    StringCollection NotSaveFields = new StringCollection();
        //    NotSaveFields.AddRange(MyTable.NotSaveFields.Split(';'));
 
        //    //生成字段列表和值列表
        //    string strFieldList = "";
        //    string strValueList = "";
        //    foreach (DataColumn col in MyTable.Columns)
        //    {
        //        //排除主键和不用保存字段。
        //        if (NotSaveFields.Contains(col.ColumnName) == true)
        //            continue;
        //        strFieldList = strFieldList == "" ? col.ColumnName : string.Format("{0},{1}", strFieldList, col.ColumnName);
        //        strValueList = strValueList == "" ? "@" + col.ColumnName : string.Format("{0},@{1}", strValueList, col.ColumnName);
        //    }
        //    string strSQL = string.Format("Insert Into {0} ({1}) Values({2})", MyTable.UpdateTable, strFieldList, strValueList);
 
        //    //创建命令
        //    SqlCommand InsertCmd = new SqlCommand(strSQL, DBConn);
 
        //    //添加参数
        //    foreach (DataColumn col in MyTable.Columns)
        //    {
        //        //排除主键和不用保存字段。
        //        if (NotSaveFields.Contains(col.ColumnName) == true)
        //            continue;
        //        SqlDbType SQLType = DataTypeMap.CSTypeToSqlType(col.DataType.Name);
        //        int Size = (col.MaxLength > 0) ? col.MaxLength : 100;
 
        //        InsertCmd.Parameters.Add("@" + col.ColumnName, SQLType, Size, col.ColumnName);
        //    }
        //    return InsertCmd;
        //}
 
        ///// <summary>
        ///// 得到删除命令
        ///// </summary>
        ///// <returns></returns>
        //public SqlCommand GetDeleteCmd(DataTable MyTable)
        //{
        //    //取得主键
        //    List<string> KeyList = new List<string>();
        //    KeyList.AddRange(MyTable.KeyField.Split(';'));
        //    if (KeyList.Count <= 0)
        //        return null;
 
        //    //生成更新语句
        //    string strSQL = string.Format("Delete {0} ", MyTable.UpdateTable);
 
        //    //根据主键设置Where条件
        //    string strWhere = "";
        //    foreach (string Key in KeyList)
        //    {
        //        strWhere = strWhere == "" ? string.Format("{0}=@{0}", Key) : string.Format("{0} and {1}=@{1}", strWhere, Key);
        //    }
        //    strSQL = string.Format("{0} where {1}", strSQL, strWhere);
        //    SqlCommand DeleteCmd = new SqlCommand(strSQL, DBConn);
 
        //    //添加参数
        //    foreach (string Key in KeyList)
        //    {
        //        DataColumn col = MyTable.Columns[Key];
        //        SqlDbType SQLType = DataTypeMap.CSTypeToSqlType(col.DataType.Name);
        //        int Size = (col.MaxLength > 0) ? col.MaxLength : 100;
        //        DeleteCmd.Parameters.Add("@" + col.ColumnName, SQLType, Size, col.ColumnName);
        //    }
 
        //    return DeleteCmd;
        //} 
    }
}