积极答复者
MSSQL中文显示???号

问题
-
本人在国内叫人做了一套net+MSSQL2005的程序
弄到国外的空间数据库中文都显示为????号
搜索了一些资料修改
varchar 改为 nvarchar
text 改为 ntext
char 改为 nchar
VALUES ('网站新闻') 改为 VALUES (N'网站新闻')
库里已经能显示中文了,但是发表出来的文章还是?????号 哪位高手帮下忙
下面是数据库脚本
if exists (select * from sysobjects where id = OBJECT_ID('[AdminUser]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [AdminUser]CREATE TABLE [AdminUser] (
[AdminId] [int] IDENTITY (1, 1) primary key NOT NULL,
[AdminUserName] [nvarchar] (255) NULL,
[AdminPwd] [nvarchar] (255) NULL)
go
INSERT [AdminUser] ([AdminUserName],[AdminPwd]) VALUES ('gameadmin','gameadmin')
INSERT [AdminUser] ([AdminUserName],[AdminPwd]) VALUES ('admin','admin')
go
if exists (select * from sysobjects where id = OBJECT_ID('[News]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [News]
go
CREATE TABLE [News] (
[NewsId] [int] IDENTITY (1, 1) primary key NOT NULL,
[NewsTitle] [nvarchar] (100) NULL,
[NewsContent] [ntext] NULL,
[NewsDate] [nvarchar] (50) NULL,
[Newstype] [int] NULL,
[Newsauthor] [nvarchar] (100) NULL,
[IsPass] [int] NULL,
[clickcount][int] NULL)
go
if exists (select * from sysobjects where id = OBJECT_ID('[NewType]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [NewType]CREATE TABLE [NewType] (
[NewTypeId] [int] IDENTITY (1, 1) PRIMARY KEY NOT NULL,
[NewTypeName] [nchar] (10) NULL)INSERT [NewType] ([NewTypeName]) VALUES (N'网站新闻')
INSERT [NewType] ([NewTypeName]) VALUES (N'心情故事')
INSERT [NewType] ([NewTypeName]) VALUES (N'经验心得')
go
if exists (select * from sysobjects where id = OBJECT_ID('[Photos]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [Photos]CREATE TABLE [Photos] (
[PhotoId] [int] IDENTITY (1, 1) primary key NOT NULL,
[BackUrl] [nvarchar] (500) NULL,
[PhotoUrl] [nvarchar] (500) NULL,
[GameName] [nvarchar] (500) NULL,
[PhotoRemark] [nvarchar] (100) NULL,
[PhotoName] [nvarchar] (100) NULL,
[PhotoType] [int] NULL,
[IsPass] [int] NULL)
go
if exists (select * from sysobjects where id = OBJECT_ID('[PhotoType]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [PhotoType]CREATE TABLE [PhotoType] (
[PhotoTypeId] [int] IDENTITY (1, 1) PRIMARY KEY NOT NULL,
[PhotoTypeName] [nvarchar] (100) NULL)INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'玩家靓照')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'游戏截图')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'合作专区')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'合作媒体')
go-- 创建默认分页存储过程
create PROCEDURE GetRecordFromPage
@tblName nvarchar(255), -- 表名
@fldName nvarchar(255), -- 字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere nvarchar(2000) = '' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL nvarchar(6000) -- 主语句
declare @strTmp nvarchar(1000) -- 临时变量
declare @strOrder nvarchar(500) -- 排序类型if @OrderType != 0
begin
set @strTmp = '<(select min'
set @strOrder = ' order by [' + @fldName + '] desc'
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by [' + @fldName +'] asc'
endset @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
+ @strOrderif @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrderif @PageIndex = 1
begin
set @strTmp = ''
if @strWhere != ''
set @strTmp = ' where (' + @strWhere + ')'set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + ']' + @strTmp + ' ' + @strOrder
endexec (@strSQL)
go
--新闻分页
create proc newsasppage
@pageSize int,
@currPage int,
@strWhere nvarchar(100)
as
declare @strsql nvarchar(500)
if
@strWhere=''
begin
set @strsql=
'select top'+ str(@pagesize)+' * from news as n inner join newtype as nt on n.newstype=nt.newtypeid where n.newsid not in
(select top'+str(@pageSize*(@currPage-1))+' newsid from news )'
end
else
begin
set @strsql=
'select top'+ str(@pagesize)+' * from news as n inner join newtype as nt on n.newstype=nt.newtypeid where n.newsid not in
(select top'+str(@pageSize*(@currPage-1))+' newsid from news ) and' +@strWhere
end
exec(@strsql)
go
--图片分页
create proc photoasppage
@pageSize int,
@currPage int,
@strWhere nvarchar(100)
as
declare @strsql nvarchar(500)
if
@strWhere=''
begin
set @strsql=
'select top'+ str(@pagesize)+' * from photos as n inner join phototype as nt on n.phototype=nt.phototypeid where n.photoid not in
(select top'+str(@pageSize*(@currPage-1))+' photoid from photos )'
end
else
begin
set @strsql=
'select top'+ str(@pagesize)+' * from photos as n inner join phototype as nt on n.phototype=nt.phototypeid where n.photoid not in
(select top'+str(@pageSize*(@currPage-1))+' photoid from photos ) and' +@strWhere
end
exec(@strsql)
答案
-
<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
或者
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
分别试试
页面里不要写
<meta http-equiv='Content-Type' content="text/html; charset=gb2312">
之类的
孟宪会- 已标记为答案 KeFang Chen 2009年4月22日 2:40
- 已标记为答案 KeFang Chen 2009年4月22日 2:43
全部回复
-
本人在国内叫人做了一套net+MSSQL2005的程序
弄到国外的空间数据库中文都显示为????号
搜索了一些资料修改
varchar 改为 nvarchar
text 改为 ntext
char 改为 nchar
VALUES ('网站新闻') 改为 VALUES (N'网站新闻')
库里已经能显示中文了,但是发表出来的文章还是?????号 哪位高手帮下忙,3Q3Q
下面是数据库脚本
if exists (select * from sysobjects where id = OBJECT_ID('[AdminUser]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [AdminUser]CREATE TABLE [AdminUser] (
[AdminId] [int] IDENTITY (1, 1) primary key NOT NULL,
[AdminUserName] [nvarchar] (255) NULL,
[AdminPwd] [nvarchar] (255) NULL)
go
INSERT [AdminUser] ([AdminUserName],[AdminPwd]) VALUES ('gameadmin','gameadmin')
INSERT [AdminUser] ([AdminUserName],[AdminPwd]) VALUES ('admin','admin')
go
if exists (select * from sysobjects where id = OBJECT_ID('[News]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [News]
go
CREATE TABLE [News] (
[NewsId] [int] IDENTITY (1, 1) primary key NOT NULL,
[NewsTitle] [nvarchar] (100) NULL,
[NewsContent] [ntext] NULL,
[NewsDate] [nvarchar] (50) NULL,
[Newstype] [int] NULL,
[Newsauthor] [nvarchar] (100) NULL,
[IsPass] [int] NULL,
[clickcount][int] NULL)
go
if exists (select * from sysobjects where id = OBJECT_ID('[NewType]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [NewType]CREATE TABLE [NewType] (
[NewTypeId] [int] IDENTITY (1, 1) PRIMARY KEY NOT NULL,
[NewTypeName] [nchar] (10) NULL)INSERT [NewType] ([NewTypeName]) VALUES (N'网站新闻')
INSERT [NewType] ([NewTypeName]) VALUES (N'心情故事')
INSERT [NewType] ([NewTypeName]) VALUES (N'经验心得')
go
if exists (select * from sysobjects where id = OBJECT_ID('[Photos]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [Photos]CREATE TABLE [Photos] (
[PhotoId] [int] IDENTITY (1, 1) primary key NOT NULL,
[BackUrl] [nvarchar] (500) NULL,
[PhotoUrl] [nvarchar] (500) NULL,
[GameName] [nvarchar] (500) NULL,
[PhotoRemark] [nvarchar] (100) NULL,
[PhotoName] [nvarchar] (100) NULL,
[PhotoType] [int] NULL,
[IsPass] [int] NULL)
go
if exists (select * from sysobjects where id = OBJECT_ID('[PhotoType]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [PhotoType]CREATE TABLE [PhotoType] (
[PhotoTypeId] [int] IDENTITY (1, 1) PRIMARY KEY NOT NULL,
[PhotoTypeName] [nvarchar] (100) NULL)INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'玩家靓照')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'游戏截图')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'合作专区')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'合作媒体')
go-- 创建默认分页存储过程
create PROCEDURE GetRecordFromPage
@tblName nvarchar(255), -- 表名
@fldName nvarchar(255), -- 字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere nvarchar(2000) = '' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL nvarchar(6000) -- 主语句
declare @strTmp nvarchar(1000) -- 临时变量
declare @strOrder nvarchar(500) -- 排序类型if @OrderType != 0
begin
set @strTmp = '<(select min'
set @strOrder = ' order by [' + @fldName + '] desc'
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by [' + @fldName +'] asc'
endset @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
+ @strOrderif @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrderif @PageIndex = 1
begin
set @strTmp = ''
if @strWhere != ''
set @strTmp = ' where (' + @strWhere + ')'set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + ']' + @strTmp + ' ' + @strOrder
endexec (@strSQL)
go
--新闻分页
create proc newsasppage
@pageSize int,
@currPage int,
@strWhere nvarchar(100)
as
declare @strsql nvarchar(500)
if
@strWhere=''
begin
set @strsql=
'select top'+ str(@pagesize)+' * from news as n inner join newtype as nt on n.newstype=nt.newtypeid where n.newsid not in
(select top'+str(@pageSize*(@currPage-1))+' newsid from news )'
end
else
begin
set @strsql=
'select top'+ str(@pagesize)+' * from news as n inner join newtype as nt on n.newstype=nt.newtypeid where n.newsid not in
(select top'+str(@pageSize*(@currPage-1))+' newsid from news ) and' +@strWhere
end
exec(@strsql)
go
--图片分页
create proc photoasppage
@pageSize int,
@currPage int,
@strWhere nvarchar(100)
as
declare @strsql nvarchar(500)
if
@strWhere=''
begin
set @strsql=
'select top'+ str(@pagesize)+' * from photos as n inner join phototype as nt on n.phototype=nt.phototypeid where n.photoid not in
(select top'+str(@pageSize*(@currPage-1))+' photoid from photos )'
end
else
begin
set @strsql=
'select top'+ str(@pagesize)+' * from photos as n inner join phototype as nt on n.phototype=nt.phototypeid where n.photoid not in
(select top'+str(@pageSize*(@currPage-1))+' photoid from photos ) and' +@strWhere
end
exec(@strsql)- 已合并 KeFang Chen 2009年4月22日 2:42
-
本人在国内叫人做了一套net+MSSQL2005的程序
弄到国外的空间数据库中文都显示为????号
搜索了一些资料修改
varchar 改为 nvarchar
text 改为 ntext
char 改为 nchar
VALUES ('网站新闻') 改为 VALUES (N'网站新闻')
库里已经能显示中文了,但是发表出来的文章还是?????号 哪位高手帮下忙
下面是数据库脚本
if exists (select * from sysobjects where id = OBJECT_ID('[AdminUser]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [AdminUser]CREATE TABLE [AdminUser] (
[AdminId] [int] IDENTITY (1, 1) primary key NOT NULL,
[AdminUserName] [nvarchar] (255) NULL,
[AdminPwd] [nvarchar] (255) NULL)
go
INSERT [AdminUser] ([AdminUserName],[AdminPwd]) VALUES ('gameadmin','gameadmin')
INSERT [AdminUser] ([AdminUserName],[AdminPwd]) VALUES ('admin','admin')
go
if exists (select * from sysobjects where id = OBJECT_ID('[News]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [News]
go
CREATE TABLE [News] (
[NewsId] [int] IDENTITY (1, 1) primary key NOT NULL,
[NewsTitle] [nvarchar] (100) NULL,
[NewsContent] [ntext] NULL,
[NewsDate] [nvarchar] (50) NULL,
[Newstype] [int] NULL,
[Newsauthor] [nvarchar] (100) NULL,
[IsPass] [int] NULL,
[clickcount][int] NULL)
go
if exists (select * from sysobjects where id = OBJECT_ID('[NewType]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [NewType]CREATE TABLE [NewType] (
[NewTypeId] [int] IDENTITY (1, 1) PRIMARY KEY NOT NULL,
[NewTypeName] [nchar] (10) NULL)INSERT [NewType] ([NewTypeName]) VALUES (N'网站新闻')
INSERT [NewType] ([NewTypeName]) VALUES (N'心情故事')
INSERT [NewType] ([NewTypeName]) VALUES (N'经验心得')
go
if exists (select * from sysobjects where id = OBJECT_ID('[Photos]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [Photos]CREATE TABLE [Photos] (
[PhotoId] [int] IDENTITY (1, 1) primary key NOT NULL,
[BackUrl] [nvarchar] (500) NULL,
[PhotoUrl] [nvarchar] (500) NULL,
[GameName] [nvarchar] (500) NULL,
[PhotoRemark] [nvarchar] (100) NULL,
[PhotoName] [nvarchar] (100) NULL,
[PhotoType] [int] NULL,
[IsPass] [int] NULL)
go
if exists (select * from sysobjects where id = OBJECT_ID('[PhotoType]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [PhotoType]CREATE TABLE [PhotoType] (
[PhotoTypeId] [int] IDENTITY (1, 1) PRIMARY KEY NOT NULL,
[PhotoTypeName] [nvarchar] (100) NULL)INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'玩家靓照')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'游戏截图')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'合作专区')
INSERT [PhotoType] ([PhotoTypeName]) VALUES (N'合作媒体')
go-- 创建默认分页存储过程
create PROCEDURE GetRecordFromPage
@tblName nvarchar(255), -- 表名
@fldName nvarchar(255), -- 字段名
@PageSize int = 10, -- 页尺寸
@PageIndex int = 1, -- 页码
@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序
@strWhere nvarchar(2000) = '' -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL nvarchar(6000) -- 主语句
declare @strTmp nvarchar(1000) -- 临时变量
declare @strOrder nvarchar(500) -- 排序类型if @OrderType != 0
begin
set @strTmp = '<(select min'
set @strOrder = ' order by [' + @fldName + '] desc'
end
else
begin
set @strTmp = '>(select max'
set @strOrder = ' order by [' + @fldName +'] asc'
endset @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
+ @strOrderif @strWhere != ''
set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
+ @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
+ @fldName + '] from [' + @tblName + '] where ' + @strWhere + ' '
+ @strOrder + ') as tblTmp) and ' + @strWhere + ' ' + @strOrderif @PageIndex = 1
begin
set @strTmp = ''
if @strWhere != ''
set @strTmp = ' where (' + @strWhere + ')'set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
+ @tblName + ']' + @strTmp + ' ' + @strOrder
endexec (@strSQL)
go
--新闻分页
create proc newsasppage
@pageSize int,
@currPage int,
@strWhere nvarchar(100)
as
declare @strsql nvarchar(500)
if
@strWhere=''
begin
set @strsql=
'select top'+ str(@pagesize)+' * from news as n inner join newtype as nt on n.newstype=nt.newtypeid where n.newsid not in
(select top'+str(@pageSize*(@currPage-1))+' newsid from news )'
end
else
begin
set @strsql=
'select top'+ str(@pagesize)+' * from news as n inner join newtype as nt on n.newstype=nt.newtypeid where n.newsid not in
(select top'+str(@pageSize*(@currPage-1))+' newsid from news ) and' +@strWhere
end
exec(@strsql)
go
--图片分页
create proc photoasppage
@pageSize int,
@currPage int,
@strWhere nvarchar(100)
as
declare @strsql nvarchar(500)
if
@strWhere=''
begin
set @strsql=
'select top'+ str(@pagesize)+' * from photos as n inner join phototype as nt on n.phototype=nt.phototypeid where n.photoid not in
(select top'+str(@pageSize*(@currPage-1))+' photoid from photos )'
end
else
begin
set @strsql=
'select top'+ str(@pagesize)+' * from photos as n inner join phototype as nt on n.phototype=nt.phototypeid where n.photoid not in
(select top'+str(@pageSize*(@currPage-1))+' photoid from photos ) and' +@strWhere
end
exec(@strsql)- 已合并 KeFang Chen 2009年4月22日 2:33
-
根据以往的经验,您必须让输出的编码统一,才能避免乱码;最好是使用 Unocode 编码来处理 Web 文字,以避免一些自行相近的简体中文影响整个画面的编码。
请注意下列事项:
1. HTML Head
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
2. ASP.NET Code
Session.CodePage=65001
Response.CharSet="UFT8"
3. 将 ASPX 利用编码的方式储存,建议使用 UTF-8 有签章 (CodePage 65001)
4. 存放在 SQL Server 字段必须使用 nchar / nvarchar ,Insert 时必须使用大写 N
知识改变命运,奋斗成就人生! -
<globalization requestEncoding="gb2312" responseEncoding="gb2312"/>
或者
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
分别试试
页面里不要写
<meta http-equiv='Content-Type' content="text/html; charset=gb2312">
之类的
孟宪会- 已标记为答案 KeFang Chen 2009年4月22日 2:40
- 已标记为答案 KeFang Chen 2009年4月22日 2:43