title: returning int value from stored procedure and check it in asp.net code to validate login form
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7645539/returning-int-value-from-stored-procedure-and-check-it-in-asp-net-code-to-valida">returning int value from stored procedure and check it in asp.net code to validate login form</a>  </p>
  </blockquote>
  
  
  
  <p>hello all please i need help in this code as it is stored procedure validate username and password , the problem here is that form validate any data even it doesn't stored in database and i tried to fix code many times but really i haven't any more thing to do in it , any one can help me to solve this problem</p>
  
  <p>this is stored procedure </p>
  
  <pre><code>set ANSI_NULLS ON
  set QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROC [dbo].[login_procedure] @username Varchar =50, @password varchar=50, @result int OUTPUT
  as
  Declare @user_name varchar , @pass_word varchar
  Set @user_name = @username
  Set @pass_word = @password
  
  if EXISTS (select @username , @password from data where username= @user_name and password=@pass_word) 
  select @result=1
  else 
  select @result=0
  </code></pre>
  
  <p>and this is asp.net code </p>
  
  <pre><code>SqlConnection conn = new SqlConnection ("Data Source=ANAGUIB-LAPNEW\\SQLEXPRESS;Initial    Catalog=account;Integrated Security=True");
     SqlCommand cmd = new SqlCommand("login_procedure", conn);
     cmd.CommandType = CommandType.StoredProcedure;
     SqlParameter paramReturnValue = new SqlParameter();
     paramReturnValue.ParameterName = "@result";
     paramReturnValue.SqlDbType = SqlDbType.Int;
     cmd.Parameters.Add(paramReturnValue);
     cmd.Parameters["@result"].Direction = ParameterDirection.Output;
     conn.Open();
  
     cmd.Parameters.AddWithValue("@username", TextBox1.Text);
     cmd.Parameters.AddWithValue("@password", TextBox2.Text);
     int resultID = Convert.ToInt32(cmd.ExecuteScalar());
     if (Convert.ToInt32(resultID) == 0)
     {
        Response.Redirect("hello.aspx");
     }
     else 
     {
        Response.Write("error");
     }
     conn.Close();
  }
  </code></pre>