<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Problema con il valore che viene restituito da stored procedures per un web method]]></title><description><![CDATA[<p dir="auto">Salve, sto creando una piccola chiamata ad un web method in <a href="http://asp.net" rel="nofollow ugc">asp.net</a> e devo eseguire una stored procedures in Sql Server che fá praticamente un INSERT e restituisce un valore (0,-1,-2,-3,-4,-5) in caso di problemi , praticamente devo eseguire la stored e restituire a video il risultato della stored ma con questo codice mi visualizza sempre il valore -1, anche se cambio la stored il valore restituito è sempre -1 quindi c'è qualcosa che non va, suggerimenti?</p>
<p dir="auto">Allego qui di seguito il codice :</p>
<pre><code>[WebMethod]
    public string RegUsuario(string salutation, string firstname, string lastname, string lastname2, int companyid, int departamentoid, int cargoid, string cargodescripcion, string emailaddress, string phonenumber, string country, string state,string usuarioweb,string pwdweb,string razonsocial)
    {
      
        using (SqlConnection conn = new SqlConnection(datosConexion))
        
        {
            conn.Open();


            SqlCommand command = new SqlCommand("sp_orb_web_personAdd", conn);
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.AddWithValue("salutation", salutation);
            command.Parameters.AddWithValue("firstname", firstname);
            command.Parameters.AddWithValue("lastname", lastname);
            command.Parameters.AddWithValue("lastname2", lastname2);
            command.Parameters.AddWithValue("companyId", companyid);
            command.Parameters.AddWithValue("departamentoid", departamentoid);
            command.Parameters.AddWithValue("cargoid", cargoid);
            command.Parameters.AddWithValue("cargoDescripcion", cargodescripcion);
            command.Parameters.AddWithValue("emailAddress", emailaddress);
            command.Parameters.AddWithValue("phoneNumber", phonenumber);
            command.Parameters.AddWithValue("country", country);
            command.Parameters.AddWithValue("state", state);
            command.Parameters.AddWithValue("usuarioWeb", usuarioweb);
            command.Parameters.AddWithValue("pwdWeb", pwdweb);
            command.Parameters.AddWithValue("razonSocial", razonsocial);


            output = command.ExecuteNonQuery().ToString();
            //output = command.ExecuteScalar().ToString();
            /*  IDataReader dr;
            dr = command.ExecuteReader();


            //List each product.
            while (dr.Read())
            {
                output = dr.GetString(0);
            }
            //Clean up.
            dr.Close(); */


       
            //output= command.ExecuteScalar().ToString();
        }




        return output;
</code></pre>
<p dir="auto">Come vedete nel codice io restituisco la variabile output a video ma mi visualizza sempre un valore che non è restituito dalla stored procedures!</p>
]]></description><link>https://dev.connect.gt/topic/217118/problema-con-il-valore-che-viene-restituito-da-stored-procedures-per-un-web-method</link><generator>RSS for Node</generator><lastBuildDate>Fri, 27 Nov 2026 22:40:34 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/217118.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 08 Sep 2015 06:17:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problema con il valore che viene restituito da stored procedures per un web method on Tue, 08 Sep 2015 12:13:08 GMT]]></title><description><![CDATA[<p dir="auto">Dopo varie ore di diventare matto ho trovato la seguente soluzione : Ho dovuto passare al command tre istruzioni, quindi non come stored procedures, ho passato il risultato della stored ad una variabile e poi l' ho stampata a video, poi ho dovuto raccogliere il valore stampato tramite il comando conn.InfoMessage e l' ho pubblicato nel Web Method.</p>
<pre><code>using (SqlConnection conn = new SqlConnection(datosConexion))
        
        {
            conn.Open();
           
            SqlCommand command = new SqlCommand("declare @pr int exec @pr = Sp_Orb_Web_PersonAdd '" + salutation + "','" + firstname + "','" + lastname + "','" + lastname2 + "'," + companyid + "," + departamentoid + "," + cargoid + ",'" + cargodescripcion + "','" + emailaddress + "','" + phonenumber + "','" + country + "','" + state + "','" + usuarioweb + "','" + pwdweb + "','" + razonsocial + "' print @pr", conn);
           


            conn.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e)
            {
                output += "\n" + e.Message;
            };


  
            command.ExecuteNonQuery().ToString();


        }
        valor = Int32.Parse(output);
</code></pre>
]]></description><link>https://dev.connect.gt/post/1206845</link><guid isPermaLink="true">https://dev.connect.gt/post/1206845</guid><dc:creator><![CDATA[crmwebs]]></dc:creator><pubDate>Tue, 08 Sep 2015 12:13:08 GMT</pubDate></item></channel></rss>