我正在尝试使用许多参数调用存储过程,但出现错误
“程序或函数‘sp_User_Create’需要参数‘@adminUser’,但未提供该参数。”
当我发送值 0
但是当我使用大于 0 的值调用存储过程时,它工作正常吗?
这是我的代码....
SqlConnection con;
SqlCommand cmd = new SqlCommand();
con = new SqlConnection("server=XXX.XXX.XXX.XXX; database=xxxxxxx; uid=xxxxxxx; pwd=xxxxx");
cmd = new SqlCommand("sp_User_Create", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("fullName", txtFirstName.Text + " " + txtLastName.Text));
cmd.Parameters.Add(new SqlParameter("emailAddress", txtEmailAddress.Text));
cmd.Parameters.Add(new SqlParameter("password", txtPassword.Text));
cmd.Parameters.Add(new SqlParameter("phoneNumber", txtPhoneNumber.Text));
cmd.Parameters.Add(new SqlParameter("jobTitle", txtJobTitle.Text));
cmd.Parameters.Add(new SqlParameter("createDate", DateTime.Now));
cmd.Parameters.Add(new SqlParameter("companyId", 116));
cmd.Parameters.Add(new SqlParameter("adminUser", 0));
cmd.Parameters.Add(new SqlParameter("userExpireDate", DateTime.Now.AddDays(7)));
cmd.Parameters.Add(new SqlParameter("userAccessLeaderboardClips", 99));
cmd.Parameters.Add(new SqlParameter("userAccessLeaderboardUsers", 99));
cmd.Parameters.Add(new SqlParameter("userAccessLeaderboardVideos", 99));
cmd.Parameters.Add(new SqlParameter("userAccessShared", 99));
cmd.Parameters.Add(new SqlParameter("userAccessEmbed", 99));
cmd.Parameters.Add(new SqlParameter("userAccessTinyUrl", 1));
cmd.Parameters.Add(new SqlParameter("userAccessAllowCreatedVideos", 1));
cmd.Parameters.Add(new SqlParameter("userAccessDownload", 99));
cmd.Parameters.Add(new SqlParameter("companyName", "My Company Name"));
cmd.Parameters.Add(new SqlParameter("logoName", "the logo name"));
cmd.Parameters.Add(new SqlParameter("postcode", "XXXX XXX"));
cmd.Parameters.Add(new SqlParameter("optIn", true));
cmd.Parameters.Add(new SqlParameter("accountType", ""));
cmd.Parameters.Add(new SqlParameter("transactionDesc", ""));
cmd.Parameters.Add(new SqlParameter("transactionDate", ""));
cmd.Parameters.Add(new SqlParameter("transactionAmount", ""));
con.Open();
cmd.ExecuteNonQuery();
con.Close();
我已经检查了存储过程,它期待:
@adminUser as int
这是存储过程:
USE [vCreateDev]
GO
/****** Object: StoredProcedure [dbo].[sp_User_Create] Script Date: 29/08/2013 10:47:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Trevor Daniel
-- Create date: 28/8/2013
-- Description: Create a user
-- =============================================
ALTER PROCEDURE [dbo].[sp_User_Create]
-- UserLogin Fields
@fullName as varchar(100),
@emailAddress as varchar(100),
@password as varchar(20),
@phoneNumber as varchar(100),
@jobTitle as varchar,
@createDate as datetime,
@companyId as int,
@adminUser as int,
@userExpireDate as datetime,
@userAccessLeaderboardClips as int,
@userAccessLeaderboardUsers as int,
@userAccessLeaderboardVideos as int,
@userAccessShared as int,
@userAccessEmbed as int,
@userAccessTinyUrl as int,
@userAccessAllowCreatedVideos as int,
@userAccessDownload int,
-- ClientCompanyDetailsPerUser
@companyName varchar(200),
@logoName varchar(200),
-- UserCustomerDetails
@postcode varchar(15),
@optIn bit,
@accountType varchar(50),
-- UserTransactions
@transactionDesc varchar(150),
@transactionDate datetime,
@TransactionAmount smallmoney
-- Outputs
--@UserLoginID INT OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
INSERT INTO UserLogin(
Username,
Password,
AuthID,
DateCreated,
LastLogin,
Fullname,
Title,
Mobile,
DDI,
Email,
AdminUser,
CompanyID,
UserExpireDate,
CurrentLogin,
LastActionDateTime,
ActiveLicense,
UserAccessLeaderboardClips,
UserAccessLeaderboardUsers,
UserAccessLeaderboardVideos,
UserAccessShared,
UserAccessEmbed,
UserAccessTinyUrl,
UserAccessAllowCreatedVideos,
UserAccessDownload)
VALUES(
@emailAddress,
@password,
null,
@createDate,
null,
@fullName,
@jobTitle,
@phoneNumber,
null,
@emailAddress,
@adminUser,
@companyId,
@userExpireDate,
null,
null,
null,
@userAccessLeaderboardClips,
@userAccessLeaderboardUsers,
@userAccessLeaderboardVideos,
@userAccessShared,
@userAccessEmbed,
@userAccessTinyUrl,
@userAccessAllowCreatedVideos,
@userAccessDownload)
DECLARE @NewUserID as int
SET @NewUserID = SCOPE_IDENTITY()
INSERT INTO ClientCompanyDetailsPerUser(CompanyName, CompanyLogoLocation, LargeCompanyLogoLocation, UserID)
VALUES (@companyName,@logoName,@logoName,@NewUserID)
INSERT INTO UserCustomerDetails(UserID, PostCode, OptIn, AccountType)
VALUES (@NewUserID,@postcode,@optIn,@accountType)
INSERT INTO UserTransactions(UserID, TransactionDesc, TransactionDate, TransactionAmount, AccountType, ResellerParameter, CampaignParameter)
VALUES (@NewUserID,@transactionDesc,@transactionDate,@TransactionAmount,@accountType,NULL,NULL)
END
我只是不明白为什么当发送零时它说参数丢失但是当我发送大于零的东西时它工作得很好?