过程需要但未提供该参数 [英] Procedure expects parameter which was not supplied
问题描述
我在访问一个存储过程中的SQL Server时,得到的错误
I'm getting the error when accessing a Stored Procedure in SQL Server
Server Error in '/' Application.
Procedure or function 'ColumnSeek' expects parameter '@template', which was not supplied.
这是发生在我调用存储过程与参数通过.NET的数据连接到SQL(System.Data.SqlClient的),即使我提供的参数。这是我的code。
This is happening when I call a Stored Procedure with a parameter through .net's data connection to sql (System.data.SqlClient), even though I am supplying the parameter. Here is my code.
SqlConnection sqlConn = new SqlConnection(connPath);
sqlConn.Open();
//METADATA RETRIEVAL
string sqlCommString = "QCApp.dbo.ColumnSeek";
SqlCommand metaDataComm = new SqlCommand(sqlCommString, sqlConn);
metaDataComm.CommandType = CommandType.StoredProcedure;
SqlParameter sp = metaDataComm.Parameters.Add("@template",SqlDbType.VarChar,50);
sp.Value = Template;
SqlDataReader metadr = metaDataComm.ExecuteReader();
和我的存储过程是:
USE [QCApp]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ColumnSeek]
@template varchar(50)
AS
EXEC('SELECT Column_Name, Data_Type
FROM [QCApp].[INFORMATION_SCHEMA].[COLUMNS]
WHERE TABLE_NAME = ' + @template);
我试图找出我在做什么错在这里。
I'm trying to figure out what I'm doing wrong here.
编辑:事实证明,模板为空,因为我是从通过URL传递参数获取其价值,我搞砸了URL参数传递(我用的是@的,而不是和&安培;)
As it turns out, Template was null because I was getting its value from a parameter passed through the URL and I screwed up the url param passing (I was using @ for and instead of &)
推荐答案
我会检查我的申请code,看看有什么价值要设置@Template来。我怀疑这是空,这其中就有问题。
I would check my application code and see what value you are setting @template to. I suspect it is null and therein lies the problem.
这篇关于过程需要但未提供该参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!