ASP.net 代码无法识别存储过程中的 OUT 参数
The OUT parameter from stored procedure is not being recognized in ASP.net code
我有一个存储过程,它给出(输出参数)数据库的最后更新时间。
我正在使用 Asp.net 中的输出参数将其显示在标签控件上。我在 asp.net 页面上收到错误消息:过程或函数 'spGetDBLastUpdatedTime' 需要参数“@LastUpdatedTime”,但未提供。
你能告诉我吗,我做错了什么。
这是存储过程:
ALTER PROCEDURE [dbo].[spGetDBLastUpdatedTime]
-- Add the parameters for the stored procedure here
@LastUpdatedTime Varchar(20) 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
SET @LastUpdatedTime =(SELECT
convert(Varchar(19),last_user_update,100) as LastUpdatedTime
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( 'EmpDB')
AND OBJECT_ID=OBJECT_ID('tblEmp'))
END
这是 asp.net 中使用它的代码。
private void GetLastUpdatedTime()
{
string cs2 = ConfigurationManager.ConnectionStrings["ConCString"].ConnectionString;
SqlConnection con2 = new SqlConnection(cs2);
using (SqlCommand command = new SqlCommand("spGetDBLastUpdatedTime", con2))
{
command.CommandType = CommandType.StoredProcedure;
//command.Parameters["@LastUpdatedTime"].Direction = ParameterDirection.Output;
SqlParameter parm = new SqlParameter("@LastUpdatedTime", SqlDbType.Int);
parm.Direction = ParameterDirection.ReturnValue;
command.Parameters.Add(parm);
con2.Open();
command.ExecuteScalar();
//LblLastUpdated.Text = (string)command.Parameters["@LastUpdatedTime"].Value;
}
}
RETURN 值与 OUTPUT 参数不同。变化:
parm.Direction = ParameterDirection.ReturnValue;
收件人:
parm.Direction = ParameterDirection.InputOutput;
或者:
parm.Direction = ParameterDirection.Output;
我有一个存储过程,它给出(输出参数)数据库的最后更新时间。 我正在使用 Asp.net 中的输出参数将其显示在标签控件上。我在 asp.net 页面上收到错误消息:过程或函数 'spGetDBLastUpdatedTime' 需要参数“@LastUpdatedTime”,但未提供。
你能告诉我吗,我做错了什么。
这是存储过程:
ALTER PROCEDURE [dbo].[spGetDBLastUpdatedTime]
-- Add the parameters for the stored procedure here
@LastUpdatedTime Varchar(20) 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
SET @LastUpdatedTime =(SELECT
convert(Varchar(19),last_user_update,100) as LastUpdatedTime
FROM sys.dm_db_index_usage_stats
WHERE database_id = DB_ID( 'EmpDB')
AND OBJECT_ID=OBJECT_ID('tblEmp'))
END
这是 asp.net 中使用它的代码。
private void GetLastUpdatedTime()
{
string cs2 = ConfigurationManager.ConnectionStrings["ConCString"].ConnectionString;
SqlConnection con2 = new SqlConnection(cs2);
using (SqlCommand command = new SqlCommand("spGetDBLastUpdatedTime", con2))
{
command.CommandType = CommandType.StoredProcedure;
//command.Parameters["@LastUpdatedTime"].Direction = ParameterDirection.Output;
SqlParameter parm = new SqlParameter("@LastUpdatedTime", SqlDbType.Int);
parm.Direction = ParameterDirection.ReturnValue;
command.Parameters.Add(parm);
con2.Open();
command.ExecuteScalar();
//LblLastUpdated.Text = (string)command.Parameters["@LastUpdatedTime"].Value;
}
}
RETURN 值与 OUTPUT 参数不同。变化:
parm.Direction = ParameterDirection.ReturnValue;
收件人:
parm.Direction = ParameterDirection.InputOutput;
或者:
parm.Direction = ParameterDirection.Output;