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();没有更新到数据库中....
请高人指点.....

解决方案 »

  1.   

    好象有一個函數要執行一下ds.ApplyUpdate();
      

  2.   

    DataSet 的 Update 方法运用的是开放锁的概念也就是说,如果你数据改变时,他会把原有数据和改变后的数据同时保存,并拿原有数据跟数据库里的记录进行比较,如果比较等同就更改数据,如果不等同就不执行相应的操作所以,我觉得你删除不了原来的记录,估计是在你的 DataSet Update 前,数据库里的记录已经被更改过了