我创建了一个具有以下签名的方法;
public bool CheckEmployeeRegistrationNo(string registrationNo, DateTime timeIn, int createdBy,
DateTime createdDate, int updatedBy, DateTime updatedDate)
{
ClsDatabaseManager dbManager = ClsDatabaseManager.InitializeDbManager();
dbManager.CreateParameters(9);
dbManager.AddParameters(0, "@RegistrationNo", registrationNo);
dbManager.AddParameters(1, "@CreatedBy", createdBy);
dbManager.AddParameters(2, "@CreatedDate", createdDate);
dbManager.AddParameters(3, "@UpdatedBy", updatedBy);
dbManager.AddParameters(4, "@UpdatedDate", updatedDate);
dbManager.AddParameters(5, "@TimeIn", timeIn);
dbManager.AddParameters(6, "@Name", EmployeeName, System.Data.ParameterDirection.Output);
dbManager.AddParameters(7, "@GeneratedTimeIn", GeneratedTimeIn, System.Data.ParameterDirection.Output);
dbManager.AddParameters(8, "@ImageUrl", ImageUrl, System.Data.ParameterDirection.Output);
int result = -1;
try
{
dbManager.Open();
result = dbManager.ExecuteNonQuery("usp_EmployeeCheckRegNo");
if (result > 0)
{
EmployeeName = dbManager.Parameters[6].Value.ToString();
GeneratedTimeIn = dbManager.Parameters[7].Value.ToDate();
ImageUrl = dbManager.Parameters[8].Value.ToString();
}
dbManager.Dispose();
}
catch (Exception ex)
{
dbManager.Dispose();
throw ex;
}
return (result != -1);
}
虽然我的存储过程看起来像;
ALTER PROC [dbo].[usp_EmployeeCheckRegNo]
(
@RegistrationNo nvarchar(50),
@TimeIn Datetime,
@CreatedBy INT,
@CreatedDate datetime,
@UpdatedBy INT,
@UpdatedDate datetime,
@Name nvarchar(50) OUT,
@GeneratedTimeIn datetime OUT,
@ImageUrl nvarchar(100) OUT
)
AS
BEGIN
if Exists
(
select RegistationNo
FROM [Employe].Registration
WHERE [RegistationNo] = @RegistrationNo
)
BEGIN
INSERT INTO [Employe].[Attendance]
(
RegistrationNo,
[TimeIn],
[CreatedBy],
[CreatedDate],
[UpdatedBy],
[UpdatedDate]
)
VALUES
(
@RegistrationNo,
@TimeIn,
@CreatedBy,
@CreatedDate,
@UpdatedBy,
@UpdatedDate
)
SET @Name = (select er.Name FROM [Employe].[Registration] er
WHERE er.[RegistationNo] = @RegistrationNo);
SET @GeneratedTimeIn = (select a.TimeIn
FROM [Employe].Attendance a
WHERE a.RegistrationNo = @RegistrationNo);
SET @ImageUrl = (select er.[Image]
FROM [Employe].[Registration] er
WHERE er.RegistationNo = @RegistrationNo);
END
ELSE
return 0
END
但是,当我在文本框中输入 2323(值)并单击按钮(在 .aspx 上)时,出现错误。我也在visual studio中调试。
错误是;
String[6]: Size 属性的大小无效为 0
为什么我在 String 6 处收到此错误?
注意:我目前正在为参数 6、7、8 提供空值,因为它们作为外参数返回。
在 sql server 中,我运行存储过程并输出预期结果;