如何在Web服务中获取最后插入的记录ID

时间:2013-03-10 15:13:43

标签: c# asp.net visual-studio-2010 web-services web

我试图在web方法执行插入后从Web服务获取插入的记录ID 但即使插入顺利,它也没有ID 如果我们知道插入方法返回bool,我怎么能在Web服务中获得该id 顺便说一下,它返回web服务中的id但是当我转到我的应用程序时它仍然为null

 if (ExecuteSqlCommand(Comm) > 0)
        {
            result = true;
            Obj.CUSTOMER_BANK_ACC_ID = (decimal)Comm.Parameters["p_CUSTOMER_BANK_ACC_ID"].Value;
        }
        return result;

1 个答案:

答案 0 :(得分:1)

我知道了 如果要在传递的对象中阻止的Web服务中返回插入的记录ID 只需通过ref传递对象,这里是代码

网络服务功能

  public bool AddObject(ref T_COMN_CUSTOMER_BANK_ACC_Entity Obj)
    {
        bool result = false;
        OracleCommand Comm = new OracleCommand(InsertCommandName, Connection);
        Comm.CommandType = CommandType.StoredProcedure;
        Comm.Parameters.Add("p_CUSTOMER_ID", OracleType.Number).Value = Obj.CUSTOMER_ID;
        Comm.Parameters.Add("p_CUSTOMER_TP_ID", OracleType.Number).Value = Obj.CUSTOMER_TP_ID;
        Comm.Parameters.Add("p_CUSTOMER_BANK_ACC_ID", OracleType.Number).Direction = ParameterDirection.Output;
        Comm.Parameters.Add("p_BANK_ID", OracleType.Number).Value = Obj.BANK_ID;
        Comm.Parameters.Add("p_IBAN", OracleType.NVarChar, 200).Value = Obj.IBAN;
        Comm.Parameters.Add("p_IS_DELETED", OracleType.Number).Value = Obj.IS_DELETED;
        Comm.Parameters.Add("p_CREATED_BY", OracleType.NVarChar, 200).Value = Obj.CREATED_BY;
        Comm.Parameters.Add("p_CREATED_DT", OracleType.DateTime).Value = Obj.CREATED_DT;
        Comm.Parameters.Add("p_MODIFIED_BY", OracleType.NVarChar, 200).Value = Obj.MODIFIED_BY;
        Comm.Parameters.Add("p_MODIFIED_DT", OracleType.DateTime).Value = Obj.MODIFIED_DT;
        if (ExecuteSqlCommand(Comm) > 0)
        {
            result = true;
            Obj.CUSTOMER_BANK_ACC_ID = (decimal)Comm.Parameters["p_CUSTOMER_BANK_ACC_ID"].Value;
        }
        return result;
    }

我在Web应用程序中调用它

pers.AddObject(ref Customer_Bank_Acc_Obj);
相关问题