returning int value from stored procedure and check it in asp.net code to validate login form

前端 未结 3 2079
太阳男子
太阳男子 2021-01-28 09:23

What is the true sequence to make this code run as I tried many time but I don\'t get a valid result

// the code of SQL stored procedure

set ANSI_NULLS          


        
相关标签:
3条回答
  • 2021-01-28 09:52

    You're executing .ExecuteScalar() so you're expecting back a result set with a single row, single column from the stored procedure - but you're not selecting anything at the end of your stored proc!

    You need to change your last line in the stored proc from

    return @result
    

    to

    SELECT @result
    

    and then it should work.

    0 讨论(0)
  • 2021-01-28 09:59

    Add another parameter for the return value

    ALTER PROC [dbo].[login_proc] 
      @username Varchar = 50, 
      @password Varchar = 50,
      @result int OUTPUT
    

    Examples can be viewd here.

    0 讨论(0)
  • 2021-01-28 10:19

    Did you try this one; Use the

    return  @result
    

    and in c#

    int resultID = Convert.ToInt32(cmd.ExecuteScalar());
    

    Also remove next line

    cmd.Parameters[""].value;
    

    I'm unable to login any suggestions, both in case of stored procedure and codebehind can anyone provide solution to this,,,plz,,,

    0 讨论(0)
提交回复
热议问题