大家好我有以下存储过程
@UserName varchar(150),
@UserEmail varchar(300),
@UserPassword varchar(150),
@ContactNumber varchar(150),
@ContactMobile varchar(150),
@AreaOfCountry varchar(150),
@UserId int OUTPUT,
@AllreadyReg int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
--DECLARE @UserId int, @AllreadyReg int
IF (SELECT COUNT(UserId) FROM Users WHERE (UserName = @UserName) OR (UserEmail = @UserEmail)) > 0
BEGIN
SET @UserId = 0
SET @AllreadyReg = 1
END
ELSE
BEGIN
INSERT INTO Users (UserName,UserEmail,UserPassword,ContactNumber,ContactMobile,AreaOfCountry) VALUES (@UserName,@UserEmail,@UserPassword,@ContactNumber,@ContactMobile,@AreaOfCountry)
SELECT @UserId = SCOPE_IDENTITY()
SET @AllreadyReg = 0
END
但是,当我使用 c# 和 asp.net 使用它时,它不返回任何内容,但是当我执行它时,它确实有一个结果 @UserId 和 @AllreadyReg 但返回值为 0 和一个字段。
我的 c# 代码在下面,但它从来没有任何行
using (SqlConnection con = new SqlConnection(connectionString))
{
Response.Write("Line 61");
using (SqlCommand cmd = new SqlCommand("spR_Register", con))
{
Response.Write("line 64");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", TxtUsername.Text.Trim());
cmd.Parameters.AddWithValue("@UserEmail", TxtEmail.Text.Trim());
cmd.Parameters.AddWithValue("@UserPassword", TxtPassword.Text.Trim());
cmd.Parameters.AddWithValue("@ContactNumber", TxtPhone.Text);
cmd.Parameters.AddWithValue("@ContactMobile", TxtMobile.Text);
cmd.Parameters.AddWithValue("@AreaOfCountry", TxtAreaOfCountry.SelectedValue);
cmd.Parameters.AddWithValue("@UserId", ParameterDirection.Output);
cmd.Parameters.AddWithValue("@AllreadyReg", ParameterDirection.Output);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
Response.Write("line 78");
etc etc
谁能帮忙
谢谢