我的SQL存取过程为:
CREATE PROCEDURE GetUserPwd
(
    @UserName varchar(100),
    @PassQusstion varchar(100),
    @PassAnswer varchar(100),
    @SqlResult  varchar(40) output
)
AS
   set  @SqlResult ='-1'
 begin
   
              SELECT  @Sqlresult=Pwd FROM Q_Users  WHERE UserName = @UserName and PassQuestion=@PassQusstion  
         and PassAnswer = @PassAnswer
end
return @Sqlresult
GO
我的c#的方法为:
public string GetUserPwd(string sUserName, string sPassQusstion, string sPassAnswer)
    {        ///创建链接
        SqlConnection myConnection = new SqlConnection(
            ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString);        ///创建Command
        SqlCommand myCommand = new SqlCommand("GetUserPwd", myConnection);
        ///设置为执行存储过程
        myCommand.CommandType = CommandType.StoredProcedure;        ///添加存储过程的参数
        SqlParameter pUserName = new SqlParameter("@UserName", SqlDbType.VarChar, 100);
        pUserName.Value = sUserName;
        myCommand.Parameters.Add(pUserName);        SqlParameter pPassQusstion = new SqlParameter("@PassQusstion", SqlDbType.VarChar, 100);
        pPassQusstion.Value = sPassQusstion;
        myCommand.Parameters.Add(pPassQusstion);
        SqlParameter pPassAnswer = new SqlParameter("@PassAnswer", SqlDbType.VarChar, 100);
        pPassAnswer.Value = sPassAnswer;
        myCommand.Parameters.Add(pPassAnswer);
        //SqlParameter sqlResult = myCommand.Parameters.Add("@sqlResult", SqlDbType.VarChar, 40);  
       // myCommand.Parameters["@sqlResult"].Direction = ParameterDirection.Output;           SqlParameter sqlResult = new SqlParameter("@SqlResult", SqlDbType.VarChar, 40);
        myCommand.Parameters.Add(sqlResult);
        //sqlResult.Direction = ParameterDirection.Output;
        myCommand.Parameters["@SqlResult"].Direction = ParameterDirection.Output;
        ///定义DataReader
        //int nResult = -1;
        try
        {
            ///打开链接
            myConnection.Open();
            ///读取数据
            // myCommand.ExecuteReader(CommandBehavior.CloseConnection);
            myCommand.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            ///抛出异常
            throw new Exception(ex.Message, ex);
        }
        finally
        {
            if (myConnection.State == ConnectionState.Open)
                myConnection.Close();
        }        ///返回DataReader
        //return nResult;
        return sqlResult.Value.ToString ();    }
我的程序在运行时报错“ 将 varchar 值 'aaaa' 转换为数据类型为 int 的列时发生语法错误。”
请教高手指点错在什么地方了,谢谢啦

解决方案 »

  1.   


    CREATE PROCEDURE GetUserPwd
    (
        @UserName varchar(100),
        @PassQusstion varchar(100),
        @PassAnswer varchar(100),
        @SqlResult  varchar(40) output
    )
    AS
      set  @SqlResult ='-1'
    begin
     
                  SELECT  @Sqlresult=Pwd FROM Q_Users  WHERE UserName = @UserName and PassQuestion=@PassQusstion 
            and PassAnswer = @PassAnswer
    end--下面一行去掉或者改为return 0 什么的,存储过程的return只能返回int型数值,
    --存储过程的输出参数不需要使用return返回,只要在存储过程中给该参数赋值就行了
    return @Sqlresult  --该行去行
    GO 
      

  2.   

    太谢谢 楼上sdfkfkd 了,可惜我现在在这里只是个新手,不能给您加分了。
      

  3.   


    Looking for ugg boots? you can buy ugg boot online. Many choices, like ugg cardyugg classic cardy,ugg classic tall,ugg classic cardy boots, etc. You can certainly find your ideal one there. The ugg boots online mall wins many customs for its unique ugg boots uk and cardy ugg bootsYou can also find cheap ugg cardy boots there.Provide the authentic links of london jewelry, including links of london sweetie braceletlinks of london charms, Necklaces, Chains, Rings, Earrings at the lowest prices possible.Hello, I purchased a foreclosed home early 2009 and I recently have noticed a very strange odor from my sewage pump or sewage lineBuy and sell Screen Printing Machine from credible manufacturers and suppliers,If you are wondering if a biometric fingerprint door lock is worth the price, you may be surprised at how affordable they are becoming.
      

  4.   


    hi .come here ugg boots is  very good .cheap ugg boots is u best choose, u will fined  ugg classic tall and ugg classic short,UGG classic mini,UGG classic leopard
    ugg boot ,UGG NEW all at my site.ugg women boots,ugg winter boot all ugg boots on sale
    come on UGG DISCOUNTugg boots sale,we like UGG CLASSI BOOTS,UGG ON SALE