0

I am working on website with C#.I have Store Registration Details in two table that is login and registration.Data is inserted in table. Now when i am on login page this email_id and pasword is selected from Database.So, for that i have created one Store procedure which is`

ALTER PROCEDURE [dbo].[P_M_Login] 


    @Email_id nvarchar(50),
    @Password nvarchar(50),
    @Tran_Type nvarchar(1)
AS
 BEGIN

SET NOCOUNT ON;

IF @Tran_Type='I'

 if not exists(select 1 from M_Login where Email_id=@Email_id)


  BEGIN   

                  INSERT INTO M_Login ( Email_id, Password) 
                  VALUES(@Email_id,@Password);
        end

ELSE
 IF @Tran_Type='S'
 BEGIN

        Select Email_id,Password from M_Login;
 END
END`

Now i want to use this Store Procedure in my three tier architecture how can i pass tran type so it will be perfect for me.

This is my DAL Class coding for calling store procedure.

     public Int32 Login(BALRegistration objBEL)
        {

            int result;
            try
            {
                SqlCommand cmd1 = new SqlCommand("P_M_Login", con);
                cmd1.CommandType = CommandType.StoredProcedure;
                //cmd.Parameters.AddWithValue("@Regisration_Id", objBEL.Registration_Id); 
                cmd1.Parameters.AddWithValue("@Email_id", objBEL.Email_id);
                cmd1.Parameters.AddWithValue("@Password", objBEL.Password);




                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                result = cmd1.ExecuteNonQuery();
                cmd1.Dispose();
                if (result > 0)
                {
                    return result;
                }
                else
                {
                    return 0;
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
            }

        }
    }
}

1 Answers1

0

Try this. Since you have parameter to be accepted in stored procedure, you just need to pass the parameter from the DAL

    string type="s";
    SqlCommand cmd1 = new SqlCommand("P_M_Login", con);
    cmd1.CommandType = CommandType.StoredProcedure;
    cmd1.Parameters.AddWithValue("@Email_id", objBEL.Email_id);
    cmd1.Parameters.AddWithValue("@Password", objBEL.Password);
    cmd1.Parameters.AddWithValue("@Tran_Type ", type);
Dani Mathew
  • 808
  • 10
  • 18
jithin john
  • 552
  • 4
  • 12