引言
在项目需求中需要用到动态批量的删除数据库中的表,我们都知道在数据库中的数据是需要历史记录的所以我
们这所谓的删除其实只是给它重命名然后打上时间戳,这样就可以标志着这个数据表在数据库中已经没有用了,但是
其中的数据还是有用的,下面和大家分享这几天在项目中学习到的东西!!
底层封装好的SQLhelper类,代码如下:
<span style="font-size:18px;">using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Transactions;
namespace ITOO.Library.Core.Common
{
/// <summary>
/// 数据库助手类
/// </summary>
public class SQLHelper
{
private SqlCommand cmd = null;
private SqlConnection conn = null;
private SqlDataReader sdr = null;
/// <summary>
///
/// </summary>
/// <param name="strDatabaseName"></param>
/// <param name="IsGetNewConnection"></param>
public SQLHelper(string strDatabaseName, bool IsGetNewConnection = false)
{
if (IsGetNewConnection == false)
{
conn = ConnectionFactory.GetCurrentConn(strDatabaseName);
}
else
{
conn = ConnectionFactory.GetNewConn(strDatabaseName);
}
}
/// <summary>
/// 无参构造函数
/// </summary>
public SQLHelper()
{
}
private SqlConnection GetConnection(string strDatabaseName)
{
string strConnValue = ConfigHelper.ReadAppSetting(strDatabaseName);
return new SqlConnection(strConnValue);
}
/// <summary>
/// 获得数据库连接
/// </summary>
/// <returns></returns>
private SqlConnection GetConnection()
{
if (conn.State == ConnectionState.Closed)
{
conn.