【问题标题】:how to get last inserted record ID within web service如何在 Web 服务中获取最后插入的记录 ID
【发布时间】:2013-02-25 18:05:07
【问题描述】:

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

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

【问题讨论】:

  • 如果 Web 服务具有 ID,则需要将其作为来自 Web 服务调用的有效负载的一部分传回。听起来 Web 服务没有这样做。
  • 为什么我不能在传递的对象中返回 id ?

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


【解决方案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);

【讨论】:

    猜你喜欢
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    相关资源
    最近更新 更多