SqlConnection sqlconn = new SqlConnection(conn);
            sqlconn.Open();
            SqlCommand sqlcomm = new SqlCommand();
            sqlcomm.Connection = sqlconn;
            sqlcomm.CommandType = CommandType.StoredProcedure;
            sqlcomm.CommandText = "proc_execchuku";
            SqlParameter[] pa ={
                              new SqlParameter("@productbianhao",SqlDbType.Int),
                              new SqlParameter("@productname",SqlDbType.NVarChar,100),
                              new SqlParameter("@outcount",SqlDbType.Int),
                              new SqlParameter("@updatetime",SqlDbType.DateTime)
                              
                              };
            for (int i = 0; i < pa.Length; i++)
            {
                sqlcomm.Parameters.Add(pa[i]);
            }
            pa[0].Value = productbianhao;
            pa[1].Value = productname;
            pa[2].Value = output;
            pa[3].Value = updatetime;
            int flag = sqlcomm.ExecuteNonQuery();
            sqlconn.Close();
            sqlconn.Dispose();
            return flag;执行时此处返回的结果为2,
但是数据库记录没变化

解决方案 »

  1.   

    1.proc_execchuku 这里面是单纯的Update吗?还是有一堆的select,.... 最后再update?
    如果不是单纯的update,这里提示的返回结果2实际上是不准确的,并不代表Update了2笔资料2.确定Update前后的值有不同吗?
      

  2.   

    Delete也一样,因为你的 proc_execchuku  没有贴出来, 输入条件也没有.光从 int flag = sqlcomm.ExecuteNonQuery(); 去判断是不准确的.
      

  3.   

    Stored Procedure的返回值不一定跟update有关系,返回什么要看sp是怎么写的...
      

  4.   

    create proc proc_ru
    @productbianhao int,
    @productname nvarchar(100),
    @outcount int,
    @updatetime datetime
    as
    declare @productid int
    begin
    begin tran
    update biao1 set count=count-@count where bianhao=@productbianhao and productname=@productname
    select productid=id from biao1 where bianhao=@productbianhao and productname=@productname
    insert into biao2 (productbianhao,productname,count,updatetime,productid) values
    (@productbianhao,@productname,@outcount,@@updatetime,@productid )
    if(@@error<>0)
    begin
    commit tran
    end
    else
    begin
    rollback tran
    end
    end
    go不好意思,大概的存储过程就是这样的了
      

  5.   

    create proc proc_ru
    @productbianhao int,
    @productname nvarchar(100),
    @outcount int,
    @updatetime datetime
    as
    declare @productid int
    begin
    begin tran
    update biao1 set count=count-@count where bianhao=@productbianhao and productname=@productname
    select productid=id from biao1 where bianhao=@productbianhao and productname=@productname
    insert into biao2 (productbianhao,productname,count,updatetime,productid) values
    (@productbianhao,@productname,@outcount,@@updatetime,@productid )
    if(@@error<>0)
    begin
    rollback tran
    end
    else
    begin
    commit tran
    end
    go
      

  6.   

    for (int i = 0; i < pa.Length; i++)
      {
      sqlcomm.Parameters.Add(pa[i]);
      }
      pa[0].Value = productbianhao;
      pa[1].Value = productname;
      pa[2].Value = output;
      pa[3].Value = updatetime;
        我以为这一句有问题,你的参数应该先赋值然后再添加进去,因此只需颠倒一下就行
      pa[0].Value = productbianhao;
      pa[1].Value = productname;
      pa[2].Value = output;
      pa[3].Value = updatetime;
    for (int i = 0; i < pa.Length; i++)
      {
      sqlcomm.Parameters.Add(pa[i]);
      }
       因为没有先赋值,系统就用默认的值代替了,如果你的数据库里正好有两条记录中某项值为默认值的话空值记录的话,那返回的当然是2了,