使用相同的存储过程插入选择

时间:2022-12-30 15:42:51

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`

我正在使用C#在网站上工作。我将商店注册详细信息放在两个登录和注册表中。数据插入表中。现在当我在登录页面时,这个email_id和pasword是从Database.So中选择的,因为我创建了一个Store程序,这是`

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.

现在我想在我的三层架构中使用这个存储过程如何通过tran类型,这对我来说是完美的。

This is my DAL Class coding for calling store procedure.

这是我用于调用存储过程的DAL类编码。

     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 个解决方案

#1


0  

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

尝试这个。由于您在存储过程中接受了参数,因此您只需要从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);

#1


0  

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

尝试这个。由于您在存储过程中接受了参数,因此您只需要从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);