【发布时间】:2020-02-10 08:45:18
【问题描述】:
我有一个存储过程,它接受一个包含非英语数据的变量。我知道我们可以使用N 这样做。但它不适用于变量。我怎样才能实现这一目标?
我想做这样的事情,但它不起作用。下面是我的存储过程。
Create Procedure tempUpdateCustomerSurvey
(
@FeedbackText nvarchar(1000)
)
As
Begin
Update tblCustomerSurvey
Set GeneralFeedbackText = @FeedbackText
Where CustomerSurveyID = 1000
End
它存储'??????'在表中。
如果我用下面的数据执行这个 SP,它就不起作用。
Declare @GeneralFeedbackText Nvarchar(1000) = 'नमस्कार'
Exec tempUpdateCustomerSurvey @GeneralFeedbackText
知道存储过程接受来自 C# 代码的数据。 下面是调用存储过程的核心 C# 方法。
public static Feedback InsertSurvey(int CustomerSurveyID, string GeneralFeedbackText)
{
try
{
int intDBReturnValue = Convert.ToInt32(SqlHelper.ExecuteScalar(SystemSettings.GetDBConnection(),
"tempUpdateCustomerSurvey",
CustomerSurveyID,
GeneralFeedbackText));
Feedback f = new Feedback(FeedbackService.DB_OP_SPECIFICATION.INSERT, intDBReturnValue, "Customer survey");
f.ProcessExceptionOrCustomErrorIfAvailable(-1, "System couldn't verify the survey information.");
return f;
}
catch (Exception ex)
{
return new Feedback(FeedbackService.DB_OP_SPECIFICATION.INSERT, ex, "Customer survey");
}
}
【问题讨论】:
-
问题在于您初始化变量值的方式 - 在您的第一个示例中,您 NOT 使用
N前缀作为字符串文字,所以它被转换回非 Unicode varchar 字符串 - 这就是为什么你会在你的表中得到这些问号.... 按设计工作 - 只是 always从字符串文字初始化nvarchar变量时使用N前缀! -
如果您已经知道第二个代码 sn-p 有效,那么您在这里问什么“我该如何实现呢?” - 使用有效的 sn-p
-
您需要显示调用代码。如果您传递的是字符串文字,它应该看起来像
EXEC tempUpdateCustomerSurvey N'Yorvalue'- 而不是EXEC tempUpdateCustomerSurvey 'Yorvalue' -
@KomalR 您刚刚删除了问题中最重要的部分。现在已经没有意义了,应该关闭为
can't reproduce。发布如何通过非英文文本的行。这就是问题所在
标签: sql sql-server stored-procedures non-english