using(SqlConnection conn = new SqlConnection(ConfigHelper.IagentDBConnectString))
{
if(conn.State!=ConnectionState.Open)
{
conn.Open();
}
SqlDataAdapter sda = new SqlDataAdapter("select * from TProductPrice where pid="+p_ProductPriceArr[0].PID,conn);
DataSet ds = new DataSet();
sda.Fill(ds); //清除PID的价格记录
ds.Tables[0].Clear(); //增加新记录
for(int i=0;i<p_ProductPriceArr.Count;i++)
{
DataRow dr = ds.Tables[0].NewRow(); dr["PID"] = p_ProductPriceArr[i].PID;
dr["LevelID"] = p_ProductPriceArr[i].LevelID ;
dr["TimeType"] = p_ProductPriceArr[i].TimeType ;
dr["TimeInt"] = p_ProductPriceArr[i].TimeInt ;
if(p_ProductPriceArr[i].UnitPrice.Length<=0)
{
dr["UnitPrice"] = System.DBNull.Value;
}
else
{
dr["UnitPrice"] = p_ProductPriceArr[i].UnitPrice ;
}
ds.Tables[0].Rows.Add(dr);
}
sda.InsertCommand = new SqlCommand();
sda.InsertCommand.Connection = conn;
sda.DeleteCommand = new SqlCommand();
sda.DeleteCommand.Connection = conn; sda.InsertCommand.CommandText = SQL_INSERT_ALL_PRODUCTPRICE;
sda.DeleteCommand.CommandText = SQL_DELETE_ONE_PRODUCTPRICE;
sda.InsertCommand.Parameters.Add(PARM_PID,SqlDbType.SmallInt,4,"PID");
sda.DeleteCommand.Parameters.Add(PARM_PID,SqlDbType.SmallInt,4,"PID");
sda.InsertCommand.Parameters.Add(PARM_LEVELID,SqlDbType.SmallInt,2,"LevelID");
sda.InsertCommand.Parameters.Add(PARM_TIMETYEP,SqlDbType.Bit,1,"TimeType");
sda.InsertCommand.Parameters.Add(PARM_TIMEINT,SqlDbType.SmallInt,2,"TimeInt");
sda.InsertCommand.Parameters.Add(PARM_UNITPRICE,SqlDbType.VarChar,20,"UnitPrice");
int Rint = sda.Update(ds);
ds.Tables[0].AcceptChanges();
return Rint;
}
删除不了原来的记录...
也就是说ds.Tables[0].Clear();没有更新到数据库中....
请高人指点.....
{
if(conn.State!=ConnectionState.Open)
{
conn.Open();
}
SqlDataAdapter sda = new SqlDataAdapter("select * from TProductPrice where pid="+p_ProductPriceArr[0].PID,conn);
DataSet ds = new DataSet();
sda.Fill(ds); //清除PID的价格记录
ds.Tables[0].Clear(); //增加新记录
for(int i=0;i<p_ProductPriceArr.Count;i++)
{
DataRow dr = ds.Tables[0].NewRow(); dr["PID"] = p_ProductPriceArr[i].PID;
dr["LevelID"] = p_ProductPriceArr[i].LevelID ;
dr["TimeType"] = p_ProductPriceArr[i].TimeType ;
dr["TimeInt"] = p_ProductPriceArr[i].TimeInt ;
if(p_ProductPriceArr[i].UnitPrice.Length<=0)
{
dr["UnitPrice"] = System.DBNull.Value;
}
else
{
dr["UnitPrice"] = p_ProductPriceArr[i].UnitPrice ;
}
ds.Tables[0].Rows.Add(dr);
}
sda.InsertCommand = new SqlCommand();
sda.InsertCommand.Connection = conn;
sda.DeleteCommand = new SqlCommand();
sda.DeleteCommand.Connection = conn; sda.InsertCommand.CommandText = SQL_INSERT_ALL_PRODUCTPRICE;
sda.DeleteCommand.CommandText = SQL_DELETE_ONE_PRODUCTPRICE;
sda.InsertCommand.Parameters.Add(PARM_PID,SqlDbType.SmallInt,4,"PID");
sda.DeleteCommand.Parameters.Add(PARM_PID,SqlDbType.SmallInt,4,"PID");
sda.InsertCommand.Parameters.Add(PARM_LEVELID,SqlDbType.SmallInt,2,"LevelID");
sda.InsertCommand.Parameters.Add(PARM_TIMETYEP,SqlDbType.Bit,1,"TimeType");
sda.InsertCommand.Parameters.Add(PARM_TIMEINT,SqlDbType.SmallInt,2,"TimeInt");
sda.InsertCommand.Parameters.Add(PARM_UNITPRICE,SqlDbType.VarChar,20,"UnitPrice");
int Rint = sda.Update(ds);
ds.Tables[0].AcceptChanges();
return Rint;
}
删除不了原来的记录...
也就是说ds.Tables[0].Clear();没有更新到数据库中....
请高人指点.....
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货