表tb ID a
01 グレーSQL="select ID,a from tb
rs.Open SQL, cnn, 3, 2msgbox rs.Fields(1) 显示 "???" 不能识别グレー,如果把表中的グレー变成:グレー 就能显示了怎么一瘦,一胖就不能识别呢,怎样才能识别瘦的
01 グレーSQL="select ID,a from tb
rs.Open SQL, cnn, 3, 2msgbox rs.Fields(1) 显示 "???" 不能识别グレー,如果把表中的グレー变成:グレー 就能显示了怎么一瘦,一胖就不能识别呢,怎样才能识别瘦的
不是在网页上显示,在程序里用个 msgbox rs.Fields(1)消息框显示,就是这样出现"?????"
如果你这一句查询语句在MSSQL里运行时看不到字符串,那就是SQL的原因,否则就是应用的原因.
有可能是进入数据库时出现的乱码;
也有可能数据库中是正常的,但是页面上显示的是乱码。
要根据实际情况来判断问题是数据库没有使用nvarchar,还是页面编码没有utf-8。
日文全角和半角,LZ写入数据库时,字段是否是unicode 或者是nvarchar类型。
处理成全角即可。参考大版的转化全半角
--2 实现全角与半角字符转换的处理函数
CREATE FUNCTION f_Convert(
@str NVARCHAR(4000), --要转换的字符串
@flag bit --转换标志,0转换成半角,1转换成全角
)RETURNS nvarchar(4000)
AS
BEGIN
DECLARE @pat nvarchar(8),@step int,@i int,@spc int
IF @flag=0
SELECT @pat=N'%[!-~]%',@step=-65248,
@str=REPLACE(@str,N' ',N' ')
ELSE
SELECT @pat=N'%[!-~]%',@step=65248,
@str=REPLACE(@str,N' ',N' ')
SET @i=PATINDEX(@pat COLLATE LATIN1_GENERAL_BIN,@str)
WHILE @i>0
SELECT @str=REPLACE(@str,
SUBSTRING(@str,@i,1),
NCHAR(UNICODE(SUBSTRING(@str,@i,1))+@step))
,@i=PATINDEX(@pat COLLATE LATIN1_GENERAL_BIN,@str)
RETURN(@str)
END
GOdeclare T_cursor cursor local for
select
a.Name, b.Name
from
sysobjects a
join
syscolumns b on a.ID=b.ID
join
systypes c on c.xusertype=b.Xtype
where
a.xtype='U' and c.Name in('nvarchar','nchar','varchar','char')
declare @tabName sysname,@ColName sysname
open T_cursor
fetch next from T_cursor into @tabName,@ColName
while @@fetch_status=0
begin
exec('update '+@tabName+' set '+@ColName+'=dbo.f_Convert('+@ColName+',0) where PATINDEX(N''%[!-~]%'' COLLATE LATIN1_GENERAL_BIN'+','+@ColName+')>0'
fetch next from T_cursor into @tabName,@ColName
end
close T_cursor
deallocate T_cursor-----------------------------------------改列的数据全角为半角
declare T_cursor cursor local for
select
a.Name, b.Name
from
sysobjects a
join
syscolumns b on a.ID=b.ID
join
systypes c on c.xusertype=b.Xtype
where
a.xtype='U' and c.Name in('nvarchar','nchar','varchar','char')
declare @tabName sysname,@ColName sysname
open T_cursor
fetch next from T_cursor into @tabName,@ColName
while @@fetch_status=0
begin
exec('update '+@tabName+' set '+@ColName+'=dbo.f_Convert('+@ColName+',0) where PATINDEX(N''%[!-~]%'' COLLATE LATIN1_GENERAL_BIN'+','+@ColName+')>0')--少了)
fetch next from T_cursor into @tabName,@ColName
end
close T_cursor
deallocate T_cursor
go
--改列名全角为半角
declare T_cursor cursor local for
select
a.Name, b.Name
from
sysobjects a
join
syscolumns b on a.ID=b.ID
where
a.xtype='U' and PATINDEX(N'%[!-~]%' COLLATE LATIN1_GENERAL_BIN,b.Name)>0
declare @tabName sysname,@ColName sysname
open T_cursor
fetch next from T_cursor into @tabName,@ColName
while @@fetch_status=0
begin
exec('exe sp_rename '''+@tabName+'.'+@ColName+''',''dbo.f_Convert('+@ColName+',0)''')
fetch next from T_cursor into @tabName,@ColName
end
close T_cursor
deallocate T_cursor------------------------------------------------------
--改列名全角为半角
declare T_cursor cursor local for
select
a.Name+'.'+b.Name,NameNew=dbo.f_Convert(b.Name)
from
sysobjects a
join
syscolumns b on a.ID=b.ID
where
a.xtype='U' and PATINDEX(N'%[!-~]%' COLLATE LATIN1_GENERAL_BIN,b.Name)>0
declare @tabName sysname,@ColName sysname
open T_cursor
fetch next from T_cursor into @tabName,@ColName
while @@fetch_status=0
begin
exe sp_rename @tabName,@ColName
fetch next from T_cursor into @tabName,@ColName
end
close T_cursor
deallocate T_cursor
declare @table1 table (col nvarchar(6))
insert into @table1
select 'グレー' union all
select 'グレー'select * from @table1
/*
col
------
????
グレー
*/
declare @table table (col nvarchar(6))
insert into @table
select N'グレー' union all
select N'グレー'select * from @table
/*
col
------
グレー
グレー
*/