我已經創建了具有以下簽名的方法;獲取例外:尺寸屬性的無效尺寸爲0
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中調試。
錯誤是; 字符串[6]:大小屬性有一個無效的大小0
爲什麼我在字符串6得到這個錯誤?
注:我目前向參數6,7,8提供空值,因爲它們是作爲超參數返回的。
雖然在SQL Server,我運行存儲過程和輸出預期的結果;
我已經運行,並使用了與參數成功地另一種方法的返回值。我也在這裏遵循同樣的道理。但它不起作用。而ClsDatabaseManager是我的課 – 2013-02-25 08:01:21
@DNet網絡漫遊器嘗試指定一個長度,看看會發生什麼。 – Snixtor 2013-02-25 08:02:30
+1將'SqlParameter.Size'設置爲50可以解決問題。感謝好友 – 2013-02-25 08:32:41