分享

写回答

发帖

[其他] GoDaddy sql 2005数据库请求帮助

GoDaddy GoDaddy 1306 人阅读 | 4 人回复

发表于 2009-4-14 20:47:00 | 显示全部楼层 |阅读模式

我导入SQL2005数据后,数据库内容都是显示?????号的。搜索了论坛一些相关帖子,在中文前加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] [varchar]  (255) NULL,
[AdminPwd] [varchar]  (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] [varchar]  (100) NULL,
[NewsContent] [text]  NULL,
[NewsDate] [varchar]  (50) NULL,
[Newstype] [int]  NULL,
[Newsauthor] [varchar]  (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] [char]  (10) NULL)

INSERT [NewType] ([NewTypeName]) VALUES ('中文新闻')
INSERT [NewType] ([NewTypeName]) VALUES ('中文故事')
INSERT [NewType] ([NewTypeName]) VALUES ('中文心得')
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] [varchar]  (500) NULL,
[PhotoUrl] [varchar]  (500) NULL,
[GameName] [varchar]  (500) NULL,
[PhotoRemark] [varchar]  (100) NULL,
[PhotoName] [varchar]  (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] [varchar]  (100) NULL)

INSERT [PhotoType] ([PhotoTypeName]) VALUES ('中文靓照')
INSERT [PhotoType] ([PhotoTypeName]) VALUES ('中文截图')
INSERT [PhotoType] ([PhotoTypeName]) VALUES ('中文专区')
INSERT [PhotoType] ([PhotoTypeName]) VALUES ('中文媒体')
go

-- 创建默认分页存储过程
create   PROCEDURE GetRecordFromPage
    @tblName      varchar(255),       -- 表名
    @fldName      varchar(255),       -- 字段名
    @PageSize     int = 10,           -- 页尺寸
    @PageIndex    int = 1,            -- 页码
    @OrderType    bit = 0,            -- 设置排序类型, 非 0 值则降序
    @strWhere     varchar(2000) = ''  -- 查询条件 (注意: 不要加 where)
AS
declare @strSQL   varchar(6000)       -- 主语句
declare @strTmp   varchar(1000)       -- 临时变量
declare @strOrder varchar(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'
end

set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
    + @tblName + '] where [' + @fldName + ']' + @strTmp + '(['
    + @fldName + ']) from (select top ' + str((@PageIndex-1)*@PageSize) + ' ['
    + @fldName + '] from [' + @tblName + ']' + @strOrder + ') as tblTmp)'
    + @strOrder

if @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 + ' ' + @strOrder

if @PageIndex = 1
begin
    set @strTmp = ''
    if @strWhere != ''
        set @strTmp = ' where (' + @strWhere + ')'

    set @strSQL = 'select top ' + str(@PageSize) + ' * from ['
        + @tblName + ']' + @strTmp + ' ' + @strOrder
end

exec (@strSQL)
go
--新闻分页
create  proc newsasppage
@pageSize int,
@currPage int,
@strWhere varchar(100)
as
declare @strsql varchar(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 varchar(100)
as
declare @strsql varchar(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)

回答|共 4 个

add.c

发表于 2009-4-16 13:39:22 | 显示全部楼层

把varchar改为nvarchar

comego

发表于 2009-4-16 14:14:38 | 显示全部楼层

我也遇到了这个问题 请留下联系方式 交流一下 QQ 86 0532 521
RAKSmart

btou

发表于 2009-4-16 18:30:57 | 显示全部楼层

原帖由 add.c 于 2009-4-16 01:39 PM 发表
把varchar改为nvarchar


varchar 改为 nvarchar
text 改为 ntext
char 改为 nchar
VALUES ('中文新闻') 改为 VALUES (N'中文新闻')

已经显示中文了,但是发表出来的文章内容还是????号。。。

add.c

发表于 2009-4-16 18:38:34 | 显示全部楼层

回复 4# 的帖子

在要插入的中文字符的引号前加N不行么?
如:
insert into theme(name,about)   values(’pusu’,’ 美国主机侦探’);
而要想在英文版的sql server中不乱码,则
insert into theme(name,about)   values(’pusu’,N’ 美国主机侦探’);
您需要登录后才可以回帖 登录 | 注册

本版积分规则