c# call stored procedure webservice

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • argavilan18
    New Member
    • Dec 2022
    • 1

    c# call stored procedure webservice

    good day everyone,

    I currently have this project where I call the parameter in this method with an XSD and it should save the data in a Stored Procedure. I have made several attempts. When entering the XSD, it only returns the XSD but does not return the output parameter.

    Here is the code:

    Code:
      internal static string ValidateCreateRequestDeductibleXml(string data)
            {
    
    
    
                DsCreateRequestDeductible dsCreateRequestDeductible = new DsCreateRequestDeductible();
    
                try
                {
                    if (!data.Equals(String.Empty))
                    {
                        System.IO.StringReader xml = new System.IO.StringReader(data);
                        dsCreateRequestDeductible.ReadXml(xml);
                        Console.WriteLine("El código es: ");
                    }
                    else
                    {
                        SqlParameter myOutputParameter = new SqlParameter("@sp_mjsError", SqlDbType.Int);
                        myOutputParameter.Direction = ParameterDirection.Output;
                    }
                }
                catch (XmlException e)
                {
                    Console.WriteLine("Error");
                }
    
                foreach (DataRow row in dsCreateRequestDeductible.Tables[0].Rows)
                {
                    CreateRequest createRequestdeductible = new CreateRequest();
                    createRequestdeductible.ProcessId = Convert.ToInt32(row["id_proceso"]);
                    createRequestdeductible.CompanyCode = Convert.ToDecimal(row["cod_cia"]);
                    createRequestdeductible.ClaimNumber = Convert.ToDecimal(row["nro_stro"]);
                    createRequestdeductible.ExcerciseYear = Convert.ToDecimal(row["aaaa_ejercicio"]);
                    createRequestdeductible.SubClaimNumber = Convert.ToDecimal(row["nro_subsiniestro"]);
                    createRequestdeductible.BranchExpCode = Convert.ToDecimal(row["cod_suc_exp"]);
                    createRequestdeductible.PrefixCode = Convert.ToDecimal(row["cod_ramo"]);
                    createRequestdeductible.RegistryDate = Convert.ToDateTime(row["fec_registro"]);
                    createRequestdeductible.RiskDescription = Convert.ToString(row["desc_riesgo"]);
                    createRequestdeductible.ItemCoverageCode = Convert.ToDecimal(row["cod_con_cob"]);
                    createRequestdeductible.ProtectionCode = Convert.ToDecimal(row["cod_amparo"]);
                    createRequestdeductible.PolicyNumber = Convert.ToDecimal(row["nro_poliza"]);
                    createRequestdeductible.AttachNumber = Convert.ToDecimal(row["nro_anexo"]);
                    createRequestdeductible.ItemNumber = Convert.ToDecimal(row["nro_item"]);
                    createRequestdeductible.DepositCode = Convert.ToDecimal(row["cod_abona"]);
                    createRequestdeductible.DocumentTypeCode = Convert.ToDecimal(row["cod_tipo_doc"]);
                    createRequestdeductible.DocumentNumber = Convert.ToString(row["nro_doc"]);
                    createRequestdeductible.SubConceptAmount = Convert.ToDecimal(row["imp_subconcepto"]);
                    createRequestdeductible.PaymentCode = Convert.ToDecimal(row["cod_con_pago"]);
                    createRequestdeductible.BillDate = Convert.ToDateTime(row["fec_factura"]);
                    createRequestdeductible.PayBranchCode = Convert.ToDecimal(row["cod_suc_gira"]);
                    createRequestdeductible.TotalPartialPayment = Convert.ToDecimal(row["pgo_total_parcial"]);
                    createRequestdeductible.StatusOperationCode = Convert.ToDecimal(row["cod_estado_op"]);
                    createRequestdeductible.EstimatedPaymentDate = Convert.ToDateTime(row["fec_estimada_pago"]);
                    createRequestdeductible.PaymentTypeCode = Convert.ToDecimal(row["cod_tipo_pago"]);
                    createRequestdeductible.PaymentNumber = Convert.ToDecimal(row["nro_pago"]);
                    createRequestdeductible.StatusCode = Convert.ToDecimal(row["cod_estado"]);
                    createRequestdeductible.UserCode = Convert.ToString(row["cod_usuario"]);
                    createRequestdeductible.ConceptCode = Convert.ToInt32(row["cod_concepto"]);
                    createRequestdeductible.FormalizedDate = Convert.ToDateTime(row["fec_formalizado"]);
                    createRequestdeductible.EstimatedCode = Convert.ToDecimal(row["cod_estim"]);
                    createRequestdeductible.ThridCode = Convert.ToDecimal(row["cod_tercero"]);
                    createRequestdeductible.CurrencyCode = Convert.ToInt16(row["cod_moneda"]);
                    createRequestdeductible.ExchangeAmount = Convert.ToDecimal(row["imp_cambio"]);
    
                    if (!(row["cod_conducto"] is DBNull))
                    {
                        createRequestdeductible.ConduitCode = Convert.ToInt16(row["cod_conducto"]);
                    }
    
    
                    if (!(row["cod_banco"] is DBNull))
                    {
                        createRequestdeductible.BankCode = Convert.ToInt16(row["cod_banco"]);
                    }
    
    
                    if (!(row["cod_moneda"] is DBNull))
                    {
                        createRequestdeductible.CurrencyCode = Convert.ToInt16(row["cod_moneda"]);
                    }
    
                    UnderWritingService2GDelegate delegateValidatePolicy = new UnderWritingService2GDelegate();
                    data = delegateValidatePolicy.ProcessCreateRequestDeductible(createRequestdeductible);
                }
                return data;
            }
    Could you help me how do I call the output parameter please? so that I read the XSD and save it in the SQL database
  • Arushi
    New Member
    • Oct 2022
    • 7

    #2
    You will need to use a SqlCommand object to call the stored procedure, and pass the output parameter as a parameter to the command. You will also need to set the SqlCommand object's CommandType property to CommandType.Sto redProcedure, and set the SqlCommand object's Parameters property to a SqlParameterCol lection object, where you can add the output parameter.

    Code:
    For example:
    
    using (SqlCommand cmd = new SqlCommand("spCreateRequestDeductible", Connection))
    {
        cmd.CommandType = CommandType.StoredProcedure;
    
        SqlParameterCollection parameters = cmd.Parameters;
        SqlParameter outputParameter = new SqlParameter("@sp_mjsError", SqlDbType.Int);
        outputParameter.Direction = ParameterDirection.Output;
        parameters.Add(outputParameter);
    
        // Add other parameters here
    
        cmd.ExecuteNonQuery();
    
        int outputValue = (int)outputParameter.Value;
        // Do something with outputValue
    }

    Comment

    Working...