我对这段代码有问题,我想要的返回变量是“Sơn”而不是“ S”
我的代码:
SentoDB.RunProcedure("usp_GetNameWithIdCategory");
SqlParameter CategoryID = new SqlParameter("CategoryID", SqlDbType.Int);
CategoryID.Value = Int32.Parse(item.Value);
SqlParameter result = new SqlParameter("result", SqlDbType.NVarChar);
result.Direction = ParameterDirection.Output;
result.Value = string.Empty;
SentoDB.AddParameters(CategoryID);
SentoDB.AddParameters(result);
SentoDB.LoadProcedure();
变量result.Value.ToString()为'S'而不是“Sơn”
public void RunProcedure(string procedureName)
{
cmd = new SqlCommand(procedureName, connect);
cmd.CommandType = CommandType.StoredProcedure;
}
public void LoadProcedure()
{
connect.Open();
cmd.ExecuteNonQuery();
connect.Close();
}
SQL中的存储过程:
CREATE PROCEDURE usp_GetNameWithIdCategory
(@CategoryID INT, @result NVARCHAR(MAX) OUTPUT)
AS
BEGIN
SELECT @result = Cate.Name
FROM Category AS Cate
WHERE Cate.CategoryID = @CategoryID
END
答案 0 :(得分:2)
尝试为参数添加大小。 在添加大小之前,我对varbinary有相同的问题。