【问题标题】:Can't store other language data in nvarchar column无法在 nvarchar 列中存储其他语言数据
【发布时间】:2018-02-06 13:08:38
【问题描述】:

我使用的是 SQL Server 2008。 这是我的表定义。

create table myTable (nid int identity(1,1),content nvarchar(max));

当我执行这两个查询时

insert into myTable(content)values(N'हिंदी में परीक्षण');
update myTable set content=N'हिंदी में परीक्षण' where nid=1;

在表中插入/更新其他语言数据。我想在存储过程中做同样的事情。这是我的存储过程的定义。

create proc myProc
@nid int,
@content nvarchar(max)
as
begin
  update myTable set content=@content where nid=@nid;
end

它只是不起作用该列更新为 ?????????????价值。我该怎么办。我试着这样做

update myTable set content=N''+@content where nid=@nid;

但这也不起作用。请帮忙。

我忘了说一件事

exec myProc 1,N'हिंदी में परीक्षण'

这当然有效,但问题是我从我使用此语法的 asp .net Web 应用程序发送数据。

public void myProcCall()
    {
        dbcommand = db.GetStoredProcCommand("myProc", nid, content);
        ds = db.ExecuteDataSet(dbcommand);
    }

因此,当我从 Web 应用程序发送其他语言内容时,值会更新为 ??????????。我是否必须对我的 asp .net 代码进行一些更改。

【问题讨论】:

  • 可以存储任何语言。您可以存储任何 UTF16 字符。 MySQL 没有nvarchar。如果你不能让它在 SQL Server 中工作,那是因为你没有发送一个 Unicode 字符串或者该字段不是 Unicode。无论加载什么文本都会破坏字符串
  • 向我们展示调用 proc 的代码。
  • BTW nvarchar(max) 适用于可以增长到 2GB 的 blob,而不是普通文本
  • 贴出调用存储过程的代码。这就是将 Unicode 转换为 ASCII 并破坏数据的原因
  • update myTable set content=N''+@content where nid=@nid; 毫无意义。首先,它在前面加上一个空字符串。第二个N'whatever' 用于字符串文字nvarchar 参数已知为 nvarchar,它不需要任何前缀。无论调用什么存储过程,都会在文本到达服务器之前破坏文本

标签: asp.net sql-server nvarchar


【解决方案1】:

这会起作用

EXEC myProc 1, N'हिं में पदी रीक्षण'

这不会

EXEC myProc 1, 'हिं में पदी रीक्षण'

所以,参数发送为非unicode

您需要确保填充参数的代码发送 unicode

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-06
    • 2012-02-16
    • 1970-01-01
    • 2013-06-01
    • 2015-09-26
    • 2011-06-01
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多