带问号的 nvarchar 列结果
nvarchar column result with question marks
我正在尝试更新队列项目并检索它的列文本内容。
问题是希伯来字符等特殊符号导致问号:????
我可以通过直接 SELECT
子句(在 sql management studio
中)完美地看到文本:
Message's column
-------
היי
hey
当我尝试检索数据时,它变得乱七八糟:
היי ---> ??? (Not OK)
hey ---> hey (OK)
我的table:
CREATE TABLE [dbo].[MyQueue](
[Message] [nvarchar](1000) NOT NULL
--some additional columns
)
这是我的存储过程:
ALTER procedure [dbo].[MyDequeue] (
)
as
begin
with CTE as (
SELECT TOP (100) *
FROM MyQueue WITH (xlock,READPAST)
WHERE Locked = 0
and HasError=0
and Success=0)
UPDATE CTE
SET Locked = 1, LockTime=getUtcDate()
OUTPUT INSERTED.*;
end
我正在通过这些功能阅读此项目:
public IEnumerable<MyQueue> Dequeue(int batchSize)
{
var cmd = dataManager.CreateCommand();
cmd.CommandText = "MyDequeue";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
using (var reader = dataManager.ExecuteReader(cmd))
{
var ordinals = reader.LoadFields();
List<MyQueue> items = new List<MyQueue>();
while (reader.Read())
{
items.Add(new MyQueue()
{
Message = reader.GetString(ordinals["Message"])
// some additional properties init
});
}
return items;
}
}
public static Dictionary<string, int> LoadFields(this IDataReader reader)
{
Dictionary<string, int> loadedColumns = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < reader.FieldCount; i++)
{
try
{
loadedColumns.Add(reader.GetName(i), i);
}
catch (System.ArgumentException) { }
}
return loadedColumns;
}
已解决(归功于@dan-guzman):
需要插入的数据带有参数化查询和字符文字N前缀。
赞:N 'היי'
.
我正在尝试更新队列项目并检索它的列文本内容。
问题是希伯来字符等特殊符号导致问号:????
我可以通过直接 SELECT
子句(在 sql management studio
中)完美地看到文本:
Message's column
-------
היי
hey
当我尝试检索数据时,它变得乱七八糟:
היי ---> ??? (Not OK)
hey ---> hey (OK)
我的table:
CREATE TABLE [dbo].[MyQueue](
[Message] [nvarchar](1000) NOT NULL
--some additional columns
)
这是我的存储过程:
ALTER procedure [dbo].[MyDequeue] (
)
as
begin
with CTE as (
SELECT TOP (100) *
FROM MyQueue WITH (xlock,READPAST)
WHERE Locked = 0
and HasError=0
and Success=0)
UPDATE CTE
SET Locked = 1, LockTime=getUtcDate()
OUTPUT INSERTED.*;
end
我正在通过这些功能阅读此项目:
public IEnumerable<MyQueue> Dequeue(int batchSize)
{
var cmd = dataManager.CreateCommand();
cmd.CommandText = "MyDequeue";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
using (var reader = dataManager.ExecuteReader(cmd))
{
var ordinals = reader.LoadFields();
List<MyQueue> items = new List<MyQueue>();
while (reader.Read())
{
items.Add(new MyQueue()
{
Message = reader.GetString(ordinals["Message"])
// some additional properties init
});
}
return items;
}
}
public static Dictionary<string, int> LoadFields(this IDataReader reader)
{
Dictionary<string, int> loadedColumns = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
for (int i = 0; i < reader.FieldCount; i++)
{
try
{
loadedColumns.Add(reader.GetName(i), i);
}
catch (System.ArgumentException) { }
}
return loadedColumns;
}
已解决(归功于@dan-guzman):
需要插入的数据带有参数化查询和字符文字N前缀。
赞:N 'היי'
.