/// <summary>
/// 把相关的ID生成一张临时表结构,并填充相关数据;
/// </summary>
/// <param name="Parameter">传送相关生成临时表的SQL语句,这样主要为了可以把保存条件临时表变得通用</param>
public byte[] ExecuteSaveTempGoodsStyleData(string tempSql, byte[] dsbyte, string sql)
{
DataSet dsRet = (DataSet)G._DeserializeObj(dsbyte);//转化成数据集
byte[] ret = null;
Database db = CreateDatabase();
SqlConnection sqlCon = null;
using (DbConnection conn = db.CreateConnection())
{
try
{
string str = sql;
sqlCon = new SqlConnection(conn.ConnectionString);
sqlCon.Open();
SqlCommand cmd = new SqlCommand(tempSql, sqlCon);//构建生成的临时表结构
int m = cmd.ExecuteNonQuery();
foreach (DataTable dt in dsRet.Tables)
{
string dtTempName = "#" + dt.TableName; //构建需要插入数据的临时表名称
SqlBulkCopy sqlBC = new SqlBulkCopy(sqlCon);//启用批量复制;
sqlBC.BulkCopyTimeout = 5000;
sqlBC.DestinationTableName = dtTempName;
sqlBC.NotifyAfter = 100;
sqlBC.WriteToServer(dt);
}
SqlDataAdapter da = new SqlDataAdapter(sql, sqlCon);
DataSet ds = new DataSet();
da.Fill(ds);
ret = G.SerializateObj(ds);
}
catch (System.Exception ex)
{
G.LogErr("ExecuteSaveTempGoodsStyleData", ex);
}
finally
{
sqlCon.Close();
}
}
return ret;
}
/// 把相关的ID生成一张临时表结构,并填充相关数据;
/// </summary>
/// <param name="Parameter">传送相关生成临时表的SQL语句,这样主要为了可以把保存条件临时表变得通用</param>
public byte[] ExecuteSaveTempGoodsStyleData(string tempSql, byte[] dsbyte, string sql)
{
DataSet dsRet = (DataSet)G._DeserializeObj(dsbyte);//转化成数据集
byte[] ret = null;
Database db = CreateDatabase();
SqlConnection sqlCon = null;
using (DbConnection conn = db.CreateConnection())
{
try
{
string str = sql;
sqlCon = new SqlConnection(conn.ConnectionString);
sqlCon.Open();
SqlCommand cmd = new SqlCommand(tempSql, sqlCon);//构建生成的临时表结构
int m = cmd.ExecuteNonQuery();
foreach (DataTable dt in dsRet.Tables)
{
string dtTempName = "#" + dt.TableName; //构建需要插入数据的临时表名称
SqlBulkCopy sqlBC = new SqlBulkCopy(sqlCon);//启用批量复制;
sqlBC.BulkCopyTimeout = 5000;
sqlBC.DestinationTableName = dtTempName;
sqlBC.NotifyAfter = 100;
sqlBC.WriteToServer(dt);
}
SqlDataAdapter da = new SqlDataAdapter(sql, sqlCon);
DataSet ds = new DataSet();
da.Fill(ds);
ret = G.SerializateObj(ds);
}
catch (System.Exception ex)
{
G.LogErr("ExecuteSaveTempGoodsStyleData", ex);
}
finally
{
sqlCon.Close();
}
}
return ret;
}