ASP读取SQL字段,总提示“类型不匹配”!!!急!!!

monday 2003-10-22 12:54:43
代码:
rs.open "select power from [user] where name='"&username&"' and valid=1",conn_system,1,1

if rs.recordcount<>0 then
session("power")=trim(rs("power")) <-----出错,提示类型不匹配
end if

power在SQL中定义为 CHAR或者VARCHAR,结果都一样,提示类型不匹配。

环境为:WIN2000+IIS5/WIN ME+PWS,SQL 2000
...全文
114 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
jgjgbb 2003-10-22
  • 打赏
  • 举报
回复
不是啊。select power的话,那后边的判断字段是找不到的。你再试试可以了吗。

sql="select * from user where name='"&username&"' and valid=1"
其实哪个方括号没有必要用的。多麻烦。你看看,现在再用RS("POWER") 读还报错吗。
monday 2003-10-22
  • 打赏
  • 举报
回复
我明白了
monday 2003-10-22
  • 打赏
  • 举报
回复
sql语句没问题,因为有返回1条记录
monday 2003-10-22
  • 打赏
  • 举报
回复
write 的结果为:select * from [user] where name='admin' and password='123456' and valid=1

我只要POWER字段,select power就可以的啊
jgjgbb 2003-10-22
  • 打赏
  • 举报
回复
改写一下:
sql="select power from [user] where name='"&username&"' and valid=1"
//你只select 一个power 那name 和valid找谁要去啊。你用* 代替power如下:
sql="select * from [user] where name='"&username&"' and valid=1"

response.write(sql)//告诉我如何显示的。
rs.open sql,conn_system,3,3
if not rs.eof then response.write("power is:"&rs("power")) 类型不匹配

在试试。对了说一声
monday 2003-10-22
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2117/2117480.xml?temp=.3779413

大家帮帮忙帮我把上面的帖子顶一下:)拜托
monday 2003-10-22
  • 打赏
  • 举报
回复
大家帮帮忙啊
monday 2003-10-22
  • 打赏
  • 举报
回复
还是提示类型不匹配
qhdsnow 2003-10-22
  • 打赏
  • 举报
回复
用下面不行吗?
session("power")=trim(cstr(rs("power")))
monday 2003-10-22
  • 打赏
  • 举报
回复
答复:

response.write session("power") 是空的
response.write rs("power") 类型不匹配

dim t
t=rs("power") 类型不匹配

rs.open "select power from [user] where name='"&username&"' and valid=1",conn_system,3,3
if not rs.eof then response.write("power is:"&rs("power")) 类型不匹配

楼上的各位都不行啊


angelheavens 2003-10-22
  • 打赏
  • 举报
回复
用下面的试试:

dim sqlStr
sqlStr="select power from [user] where name='"&username&"' and valid=1"
rs.open sqlStr,conn_system,1,1
if rs.recordcount>0 then
session("power")=trim(rs("power"))
end if
ndq2002 2003-10-22
  • 打赏
  • 举报
回复
我不知道问题出在那里,但假如是我发现这个问题,我会:
1.response.write session("power")
response.write rs("power")
看一下有没有什么明显差别
2.下一步试一下强制类型转换看行不行.
3.再不行则加入一下中间变量,分别赋值后把变量类型输出!
4.暂时没有想到其它
jgjgbb 2003-10-22
  • 打赏
  • 举报
回复
rs.open "select power from [user] where name='"&username&"' and valid=1",conn_system,3,3
if not rs.eof then

response.write("power is:"&rs("power"))

后,看看屏幕上如何显示。
yangsm 2003-10-22
  • 打赏
  • 举报
回复
关注……
tigerwen01 2003-10-22
  • 打赏
  • 举报
回复
去掉IF语句试试

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧