Different value in the stored procedure and the return variable

微信扫一扫,分享到朋友圈

Different value in the stored procedure and the return variable

I have two instances in my login page depending on what is returned as vat (return variable from the stored procedure below), when I execute the stored procedure on the server the result is INTERNAL
, but the the condition on else
gets executed instead of INTERNAL
on the login page.

string usertype = u.ViewUserType((int)Session["Id"]);
string vattype = u.ViewUserVat((string)Session["Code"]);                         

if (usertype == "Client")
{
   if (vattype == "INTERNAL")
   {
      Response.Redirect("~/NonIFAClient/");
   }
   else
   {
      Response.Redirect("~/Client/");
   }
}

public string ViewUserVat(string code)
{
   CamOnlineAccess.Utilities u = new CamOnlineAccess.Utilities();
   SqlCommand c = u.GetCommandSP("dbo.ViewUserVat");

   c.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] {
       new System.Data.SqlClient.SqlParameter("@code",System.Data.SqlDbType.VarChar,50),
       new System.Data.SqlClient.SqlParameter("@vat",SqlDbType.VarChar, 50, System.Data.ParameterDirection.Output, false, ((byte)(0)), ((byte)(0)), "", System.Data.DataRowVersion.Current, null)});

   c.Parameters["@code"].Value = code;

   c.Connection.Open();
   c.ExecuteScalar();   // because we have output parameters
   c.Connection.Close();

   return (string)c.Parameters["@vat"].Value;
}

Stored procedure:

ALTER PROCEDURE [dbo].[ViewUserVat]
      -- Add the parameters for the stored procedure here
      @code varchar,
      @vat varchar(50) output
AS
  SELECT
      TOP 1 @vat = vattable
  FROM
      dbo.portfolio
  WHERE
      owner = @code

Maybe there are spaces or casting issues in the comparrisson

try

c.ExecuteScalar();//because we have output parameters
c.Connection.Close();

String value = (string)c.Parameters["@vat"].Value;

value = value.Trim().ToUpper();

return (string)c.Parameters["@vat"].Value;

微信扫一扫,分享到朋友圈

Different value in the stored procedure and the return variable

时尚单品来袭 vivo LOGO PHONE开售

上一篇

DOM Exception 12 when trying to stream MP3 through websocket

下一篇

你也可能喜欢

Different value in the stored procedure and the return variable

长按储存图像,分享给朋友