/// <summary>
/// SQL server 类库
/// 版本 1.00 修改时间 2016-01-15
/// 版本 1.01 修改时间 2016-01-18 修改内容 增加服务器时间到毫秒的说明
//数据库连接字符串(web.config来配置),多数据库可使用DbHelperSQLP来实现.
public static string connectionString;
/// <summary>构造函数(初始化)
/// 构造函数(初始化)
/// </summary>
/// <param name="connect"></param>
public Class_数据库SQL(string connect)
{
connectionString = connect;
}
/// <summary>SQL查询返回DataSet
/// SQL查询返回DataSet
/// </summary>
/// <param name="CmdString1">SQL语句</param>
/// <param name="表名">返回DataSet数据集的表名</param>
/// <returns></returns>
public DataSet SQL_Select_DataSet(string CmdString1, string 表名)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlDataAdapter SqlDA = new SqlDataAdapter(CmdString1, connection))
{
try
{
using (DataSet DataSet1 = new DataSet())
{
connection.Open();
SqlDA.Fill(DataSet1, 表名);
if (DataSet1.Tables.Count == 0)
{
Thread.Sleep(100);
SqlDA.Fill(DataSet1, 表名);
}
return DataSet1;
}
}
catch (System.Data.SqlClient.SqlException e)
{
connection.Close();
throw e;
}
}
}
}
public void SQL_Select_DataSet_SAVE(DataSet DataSet1,string CmdString1,string 表名)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlDataAdapter SqlDA = new SqlDataAdapter(CmdString1, connection))
{
try
{
using (DataSet DataSet11 = new DataSet())
{
connection.Open();
SqlDA.Fill(DataSet11, 表名);
if (DataSet11.Tables.Count == 0)
{
Thread.Sleep(100);
SqlDA.Fill(DataSet11, 表名);
}
DataSet1.AcceptChanges();
SqlDA.Update(DataSet11.GetChanges());
}
}
catch (System.Data.SqlClient.SqlException e)
{
connection.Close();
throw e;
}
}
}
}
。。。
评论