我正在使用C#在網站上工作。我在兩個表中登錄和註冊了Store註冊詳細信息.Data被插入到表中。現在,當我登錄頁面上此EMAIL_ID和pasword從Database.So選擇,對於我創建了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 protected]_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`
現在,我想在我的三層架構如何使用這個存儲過程一個存儲過程我可以通過tran類型,所以它對我來說是完美的。
這是我的調用存儲過程的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();
}
}
}
}
}
檢查[this](https://stackoverflow.com/questions/1260952/how-to-execute- a-stored-procedure-within-c-sharp-program) –
你可以提供調用這個存儲過程的現有代碼嗎? – zzT
https://www.aspsnippets.com/Articles/GridView-CRUD-Select-Insert-Edit-Update-Delete-using-Single-Stored-Procedure-in-ASPNet.aspx –