步骤insertSerial没有参数并提供的参数 [英] Procedure insertSerial has no parameters and arguments were supplied
本文介绍了步骤insertSerial没有参数并提供的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是存储在服务器上MSSQL我的SP。
Below is my SP stored in MSSQL server.
USE [testdb]
GO
/****** Object: StoredProcedure [dbo].[insertSerial] Script Date: 11/05/2012 16:38:20 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[insertSerial]
AS
DECLARE @start int
DECLARE @end int
DECLARE @expdate datetime
BEGIN TRAN
WHILE @start < @end
BEGIN
INSERT tbl_serial VALUES (@start, @expdate)
SET @start = @start + 1
END
COMMIT TRAN
然后我尝试这样我的ASP.NET应用程序调用的SP -
and then I try to call the SP from my ASP.NET application like this -
SqlConnection sqlconn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString);
SqlCommand cmd = new SqlCommand("insertSerial", sqlconn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@start", txtStart.Text);
cmd.Parameters.AddWithValue("@end", txtEnd.Text);
cmd.Parameters.AddWithValue("@expdate", System.DateTime.Now);
try
{
sqlconn.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
lblStatus.Text = ex.Message;
}
finally
{
sqlconn.Close();
}
然后,我得到了这个程序insertSerial没有参数并提供的参数。
错误。难道是因为我在SP声明参数的方式是不正确?如果是这样,我该如何解决这些问题?
Then I got this Procedure insertSerial has no parameters and arguments were supplied.
error. Is it because the way I declare parameters in SP is incorrect? If so, how do I fix them?
推荐答案
在SP是无效的SQL
The sp is invalid sql
这是如何声明PARAMS
This is how to declare params
ALTER PROCEDURE [DBO]。[富]
@bar INT
如
BEGIN
这篇关于步骤insertSerial没有参数并提供的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文