我是sql的新手,所以只是想知道是否有人可以提供帮助。
我有一个供应商会话ID,该ID链接到数据库中的userid。我的用户必须单击一个标志声明复选框,但是我对作为存储过程必须传递的内容感到困惑... < / p>
protected void CheckAccept_CheckedChanged(object sender, EventArgs e)
{
string declaration;
if (CheckAccept.Checked)
{
declaration = "y";
}
else
{
declaration = "N";
}
USE [SAPSupplierProductUpdate]
GO
/****** Object: StoredProcedure [dbo].[uspConfirmDeclaration] Script Date: 21/09/2018 08:28:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
ALTER PROCEDURE [dbo].[uspConfirmDeclaration]
@VendorId nvarchar(256),
@Declaration char(1)
AS
BEGIN
DECLARE @UserId uniqueidentifier
SELECT @UserId = NULL
SELECT @UserId = u.UserId
FROM dbo.aspnet_Users u, dbo.aspnet_Membership m
WHERE LoweredUserName = LOWER(@VendorId) AND
u.UserId = m.UserId
IF (@UserId IS NULL)
RETURN(1)
UPDATE dbo.aspnet_Membership
SET Declaration = @Declaration
WHERE @UserId = UserId
RETURN(0)
END
不确定如何传入Y或N
答案 0 :(得分:0)
如有其他疑问,请提供您尝试的代码示例。
由于您要查找的是未选中的复选框,因此这意味着只有两个可能/有效的选项(选中或未选中)。在只有两个且恰好两个结果的情况下,最好的做法是使用布尔值/位参数。对于您的应用程序,您将需要确保复选框以假(0)状态开始并且仅在选中时才变为true(1)。在您的存储过程中,有一个简单的IF语句,该语句检查此值,然后继续进行其余的代码。
T-SQL示例:
(@checkedBox bit = 0) -- this is your parameter at the beginning of the procedure
BEGIN
IF @checkedBox = 0
-- Do nothing, box not checked
ELSE -- This is okay since only two outcomes.
-- Do work (put your select, update, delete, whatever it is here)
END