有没有一种方法,以确定是否在存储过程的参数在代码中有一个默认值(因此不要求) - .NET? [英] Is there a way to determine if a parameter in a stored proc has a default value (and thus not required) in code - .Net?
问题描述
我已经从存储过程拉动的参数在发送这样的:
I am already pulling the parameters from the stored proc sent in like this:
foreach (SqlParameter param in cmd.Parameters)
{
if ((param.Direction == ParameterDirection.Input) || (param.Direction == ParameterDirection.InputOutput))
{
jsonReturn += "{\"paramName\":\"" + param.ParameterName + "\", \"paramType\":\"" + param.SqlDbType.ToString() + "\"},";
}
}
我看着的SqlParameter对象,找不到这样,看它是否能告诉我参数是否有默认值...(虽然我的调试器怪怪的,所以谁知道)。
I looked into the SqlParameter object and could not find a way to see if it could tell me whether the Parameter had a default value... (although my debugger is acting weird, so who knows).
我在做什么正在建设一种存储过程帮手的用户。我现在告诉他们,属于他们挑存储过程的所有参数....我真的很希望能够告诉他们是否是必需的。
What I am doing is building a sort of Stored Proc helper for users.. I currently tell them all the parameters that belong to the Stored Proc they pick.... I WOULD REALLY like to be able to tell whether they are required.
推荐答案
要直接回答你的问题,不存在(可能)没有办法确定一个存储过程的参数拥有默认值代码(即使用的SqlParameter
类)。
To directly answer your question, no there is (probably) no way to determine if a stored procedure parameter possesses a default value 'in code' (i.e. using the SqlParameter
class).
在SQL服务器(至少在SQL Server 2005中) ,你可以查询系统目录视图 sys.parameters
(并将它加入到目录视图 sys.procedures
)和评估列 has_default_value
。
In SQL Server (at least SQL Server 2005), you can query the system catalog view sys.parameters
(and join it to the catalog view sys.procedures
) and evaluate the value of the column has_default_value
.
这篇关于有没有一种方法,以确定是否在存储过程的参数在代码中有一个默认值(因此不要求) - .NET?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!