过程或函数指定的参数太多 winform c#
Procedure or function has too many arguments specified winform c#
SqlCommand cmmd = new SqlCommand("INSERT into Vows(MemberID, VowAmount, VowDate, Description) Values (@MemberID, @vowAmount, @vowDate, @vowDesc)", con);
SqlCommand storedprocedure = new SqlCommand("UPDATEINCOME", con);
storedprocedure.CommandType = CommandType.StoredProcedure;
storedprocedure.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date)).Value = vowdateTime.Text;
SqlCommand insertStoredProcedure = new SqlCommand("InsertIncomeDate", con);
insertStoredProcedure.CommandType = CommandType.StoredProcedure;
insertStoredProcedure.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date)).Value = vowdateTime.Text;
insertStoredProcedure.Parameters.Add("@IncomeDate", SqlDbType.Date).Direction = ParameterDirection.Input;
insertStoredProcedure.Parameters.Add("@IncomeDate", SqlDbType.Date).Direction = ParameterDirection.Input;
这是我的代码,我得到的错误是:
Procedure or function has too many arguments specified
cmmd.Parameters.AddWithValue("@MemberID", vowMemID.Text);
cmmd.Parameters.AddWithValue("@vowAmount", vowAmount.Text);
cmmd.Parameters.AddWithValue("@vowDate", vowdateTime.Text);
cmmd.Parameters.AddWithValue("@vowDesc", vowDescBox.Text);
cmmd.ExecuteNonQuery();
insertStoredProcedure.ExecuteNonQuery(); // error occurs here
insertStoredProcedure.Parameters.Clear();
storedprocedure.ExecuteNonQuery(); // and here
storedprocedure.Parameters.Clear();
这些是存储过程:
ALTER PROCEDURE [dbo].[UPDATEINCOME]
(@IncomeDate date, @VowAmount money)
AS
Declare @TitheAmount money
Declare @OfferingAmount money
Declare @IncomeTotal money
IF NOT EXISTS (Select VowDate from Vows where VowDate = @IncomeDate)
BEGIN
set @VowAmount = '0'
END
ELSE
BEGIN
set @VowAmount = (Select VowAmount from Vows where VowDate = @IncomeDate)
END
IF NOT EXISTS (Select OfferingDate from Offering where OfferingDate = @IncomeDate)
BEGIN
set @OfferingAmount = '0'
END
ELSE
BEGIN
set @OfferingAmount = (Select OfferingAmount from Offering where OfferingDate = @IncomeDate)
END
IF NOT EXISTS (Select TitheDate from Tithe where TitheDate = @IncomeDate)
BEGIN
set @TitheAmount = '0'
END
ELSE
BEGIN
Set @TitheAmount = (Select TitheAmount from Tithe where TitheDate = @IncomeDate)
END
Set @IncomeTotal = @TitheAmount + @VowAmount + @OfferingAmount
UPDATE IncomeReport
SET Amount = @IncomeTotal
WHERE IncDATE = @IncomeDate
UPDATEINCOME
存储过程更新 IncomeReport
table。它将此处指定为 IncomeDate
的特定日期的所有金额相加,并将总数插入 IncomeReports
.
与此同时,INsertDate
存储过程检查 IncomeReport
table 是否具有 'cmmd' 命令打算插入金额的日期。如果没有,它也会插入从 IncomeDate
获得的日期。然后,这允许 UPDATEINCOME
在日期为 @IncomeDate
.
的 table 中插入一个金额
您正在添加两个 @IncomeDate
参数。不要那样做 ;p
storeproc.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date)).Value = vowdateTime.Text;
...
storeproc.Parameters.Add("@IncomeDate", SqlDbType.Date).Direction = ParameterDirection.Input;
和(正如 Sriram 在评论中指出的那样):
storedprocedure.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date)).Value = vowdateTime.Text;
...
storedprocedure.Parameters.Add("@IncomeDate", SqlDbType.Date).Direction = ParameterDirection.Input;
如果需要,您可以捕获 Parameters.Add
:
的结果
var p = storeproc.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date));
p.Value = vowdateTime.Text;
p.Direction = ParameterDirection.Input;
但是 Input
是默认值 无论如何。
不过,坦率地说,你让这件事变得很困难。我在这里强烈推荐像 "dapper" 这样的工具:
DateTime when = ...
decimal amount = ...
connection.Execute("UPDATEINCOME",
new { IncomeDate = when, VowAmount = amount },
commandType: CommandType.StoredProcedure);
任务完成。
SqlCommand cmmd = new SqlCommand("INSERT into Vows(MemberID, VowAmount, VowDate, Description) Values (@MemberID, @vowAmount, @vowDate, @vowDesc)", con);
SqlCommand storedprocedure = new SqlCommand("UPDATEINCOME", con);
storedprocedure.CommandType = CommandType.StoredProcedure;
storedprocedure.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date)).Value = vowdateTime.Text;
SqlCommand insertStoredProcedure = new SqlCommand("InsertIncomeDate", con);
insertStoredProcedure.CommandType = CommandType.StoredProcedure;
insertStoredProcedure.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date)).Value = vowdateTime.Text;
insertStoredProcedure.Parameters.Add("@IncomeDate", SqlDbType.Date).Direction = ParameterDirection.Input;
insertStoredProcedure.Parameters.Add("@IncomeDate", SqlDbType.Date).Direction = ParameterDirection.Input;
这是我的代码,我得到的错误是:
Procedure or function has too many arguments specified
cmmd.Parameters.AddWithValue("@MemberID", vowMemID.Text);
cmmd.Parameters.AddWithValue("@vowAmount", vowAmount.Text);
cmmd.Parameters.AddWithValue("@vowDate", vowdateTime.Text);
cmmd.Parameters.AddWithValue("@vowDesc", vowDescBox.Text);
cmmd.ExecuteNonQuery();
insertStoredProcedure.ExecuteNonQuery(); // error occurs here
insertStoredProcedure.Parameters.Clear();
storedprocedure.ExecuteNonQuery(); // and here
storedprocedure.Parameters.Clear();
这些是存储过程:
ALTER PROCEDURE [dbo].[UPDATEINCOME]
(@IncomeDate date, @VowAmount money)
AS
Declare @TitheAmount money
Declare @OfferingAmount money
Declare @IncomeTotal money
IF NOT EXISTS (Select VowDate from Vows where VowDate = @IncomeDate)
BEGIN
set @VowAmount = '0'
END
ELSE
BEGIN
set @VowAmount = (Select VowAmount from Vows where VowDate = @IncomeDate)
END
IF NOT EXISTS (Select OfferingDate from Offering where OfferingDate = @IncomeDate)
BEGIN
set @OfferingAmount = '0'
END
ELSE
BEGIN
set @OfferingAmount = (Select OfferingAmount from Offering where OfferingDate = @IncomeDate)
END
IF NOT EXISTS (Select TitheDate from Tithe where TitheDate = @IncomeDate)
BEGIN
set @TitheAmount = '0'
END
ELSE
BEGIN
Set @TitheAmount = (Select TitheAmount from Tithe where TitheDate = @IncomeDate)
END
Set @IncomeTotal = @TitheAmount + @VowAmount + @OfferingAmount
UPDATE IncomeReport
SET Amount = @IncomeTotal
WHERE IncDATE = @IncomeDate
UPDATEINCOME
存储过程更新 IncomeReport
table。它将此处指定为 IncomeDate
的特定日期的所有金额相加,并将总数插入 IncomeReports
.
与此同时,INsertDate
存储过程检查 IncomeReport
table 是否具有 'cmmd' 命令打算插入金额的日期。如果没有,它也会插入从 IncomeDate
获得的日期。然后,这允许 UPDATEINCOME
在日期为 @IncomeDate
.
您正在添加两个 @IncomeDate
参数。不要那样做 ;p
storeproc.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date)).Value = vowdateTime.Text;
...
storeproc.Parameters.Add("@IncomeDate", SqlDbType.Date).Direction = ParameterDirection.Input;
和(正如 Sriram 在评论中指出的那样):
storedprocedure.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date)).Value = vowdateTime.Text;
...
storedprocedure.Parameters.Add("@IncomeDate", SqlDbType.Date).Direction = ParameterDirection.Input;
如果需要,您可以捕获 Parameters.Add
:
var p = storeproc.Parameters.Add(new SqlParameter("@IncomeDate", SqlDbType.Date));
p.Value = vowdateTime.Text;
p.Direction = ParameterDirection.Input;
但是 Input
是默认值 无论如何。
不过,坦率地说,你让这件事变得很困难。我在这里强烈推荐像 "dapper" 这样的工具:
DateTime when = ...
decimal amount = ...
connection.Execute("UPDATEINCOME",
new { IncomeDate = when, VowAmount = amount },
commandType: CommandType.StoredProcedure);
任务完成。