【发布时间】:2019-06-16 19:56:11
【问题描述】:
这段代码有问题,我想要的返回变量是“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
【问题讨论】:
标签: c# sql-server winforms sqlcommand