title: asp net check if username exists C# procedure
body: <p>I created the Procedure and added it to Load page, my code looks like that now:</p>
  
  <p><strong>Procedure:</strong></p>
  
  <pre><code>CREATE PROCEDURE  CheckIfUserExists   
  (    
      @UserName Varchar(50),  
      @IsExists INT OUTPUT   
  )   
  AS      
  
  If exists (select Nazwa_uzytkownika from Uzytkownicy where Nazwa_uzytkownika = @UserName)   
  Begin
  
  Set @IsExists = 1
  
  End     
  Else   
  begin
  
  Set @IsExists = 0
  
  End
  
  Return @IsExists
  </code></pre>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>namespace Komis_Samochodowy1
  {
      public partial class Rejestracja : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
              SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["registrationConn"].ConnectionString);
              conn.Open();
  
              SqlCommand cmd = new SqlCommand("CheckIfUserExists", conn);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.AddWithValue("@UserName", un.Text);
              **int rowAffected = cmd.ExecuteNonQuery();**    //Error
  
              if (rowAffected == 1)
              {
                  status.Visible = true;
                  status.Text = "Uzytkownik istnieje.";
              }
          }
          protected void Button4_Click(object sender, EventArgs e)
          {
              Response.Redirect("Login.aspx");
          }
  
          protected void Button1_Click(object sender, EventArgs e)
          {
              Response.Redirect("Main.aspx");
          }
  
          protected void Button3_Click(object sender, EventArgs e)
          {
              Response.Redirect("AboutMe.aspx");
          }
  
          protected void Button2_Click(object sender, EventArgs e)
          {
              Response.Redirect("Offer.aspx");
          }
  
          protected void Button5_Click(object sender, EventArgs e)
          {
              Response.Redirect("Registration.aspx");
          }
  
          protected void Button7_Click(object sender, EventArgs e)
          {
  
              SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["registrationConn"].ConnectionString);
              conn.Open();
              string dodajQuery = "insert into Uzytkownicy (Nazwa_uzytkownika, Kraj, Hasło, Email) values (@Unazwa, @ukraj, @uhasło, @uemail) ";
              SqlCommand com = new SqlCommand(dodajQuery, conn);
              com.Parameters.AddWithValue("@Unazwa", un.Text.ToString());
              com.Parameters.AddWithValue("@ukraj", country.SelectedItem.ToString());
              com.Parameters.AddWithValue("@uhasło", pass.Text.ToString());
              com.Parameters.AddWithValue("@uemail", email.Text.ToString());
              com.ExecuteNonQuery();
  
              Response.Redirect("Login.aspx");
              Response.Write("Rejestracja zakonczona.");
              conn.Close();
  
  
          }
      }
  }
  </code></pre>
  
  <p>Still doesn't work at all, it crush every time on bolted part, what i did wrong?</p>
  
  <p>Additional information: Procedure or function 'CheckIfUserExists' expects parameter '@IsExists', which was not supplied.</p>