【问题标题】:Update non-English data in stored procedure using a variable? [closed]使用变量更新存储过程中的非英语数据? [关闭]
【发布时间】: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");
           }
      }

【问题讨论】:

标签: sql sql-server stored-procedures non-english


【解决方案1】:

问题来了

Declare @FeedbackText nvarchar(1000) = 'नमस्कार'

你应该像这样使用N前缀

Declare @FeedbackText nvarchar(1000) = N'नमस्कार'

看下图就知道它们之间的区别了

【讨论】:

  • 请正确阅读我的问题。我知道为字符串添加前缀 N 是可行的,但我有一个动态 SP,它接受来自 C# 代码的数据。
  • 所以你只需声明@FeedbackText参数的类型是Nvarchar(1000)
  • 它不起作用。
  • @KomalR - 你的问题没有提到任何关于“动态 SP”(无论是什么),也不清楚你的问题是什么。如果您要创建字符串文字,请在其后面加上N。如果您使用的是参数,请确保它是nvarchar。如果您的代码不起作用,请将其添加到您的问题中,以便我们查看您做错了什么。
  • @KomalR 发布您的代码。该变量是一个字符串,但是如何传递该参数?您是否使用了字符串连接?那是一个错误。您是否使用了参数化查询?你为参数指定了什么类型? NVarchar 还是 Varchar?如果您使用字符串连接,您是否使用了N 前缀?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-01-09
  • 1970-01-01
  • 1970-01-01
  • 2013-07-16
  • 1970-01-01
  • 2021-11-09
  • 1970-01-01
相关资源
最近更新 更多