数据库怎么都不能更新!

hekunharris 2004-04-30 01:54:21
<%
str_user_account=Trim(Request.Form("str_user_account"))
str_user_code=Trim(Request.Form("str_user_code"))
set rs= Server.CreateObject("adodb.recordset")
sql="select * from [user]"
rs.open sql,conn,1,3
rs.addnew
rs_2("str_user_account")=str_user_account
rs_2("str_user_code")=str_user_code
rs.update
rs.close
%>
以上的代码,我怎么都不能更新数据库,我用response.write(str_user_account)都可以显出来,我用手工修改数据库
<%
sql="select * from [user]"
rs.open sql,conn,1,3
rs.addnew
rs_2("str_user_account")="hekunharris"
rs_2("str_user_code")="123"
rs.update
rs.close
%>
就可以修改数据库了。数据格式没有问题,请问高手能指点一下迷津!谢了先
...全文
86 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanechng 2004-04-30
  • 打赏
  • 举报
回复
if not rs.eof and not rs.bof then
后面的代码不会执行,因为rs.bof为true

没必要进行条件判断,还有rs.addnew
anwell 2004-04-30
  • 打赏
  • 举报
回复
sql="select * from [user] where = '"&request("str_user_account")&"'"
rs.open sql,1,3
if not rs.eof and not rs.bof then
rs("str_user_account")=request("str_user_account")
rs("str_user_code")=request("str_user_code")

rs.update
response.write "更新成功!"
else
response.write "用户未发现!"
end if
rs.close
set rs=nothing
hhzh426 2004-04-30
  • 打赏
  • 举报
回复
提示什么错误?
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
难道就不能用recordset来添加了吗??
chichuli_4 2004-04-30
  • 打赏
  • 举报
回复
str_user_account=Trim(Request.Form("str_user_account"))
str_user_code=Trim(Request.Form("str_user_code"))
set rs= Server.CreateObject("ADODB.CONNECTION")
rs.open "DRIVER={SQL Server};SERVER=xx;UID=xx;DATABASE=xx"
sql="insert user(str_user_account,str_user_code) values("&str_user_account&","&str_user_code&")"
rs.execute(sql)
zmhqyw 2004-04-30
  • 打赏
  • 举报
回复
是提示错误还是成功之后不能读取?
chichuli_4 2004-04-30
  • 打赏
  • 举报
回复
是不是数据类型不一样,
int ,clng,cstr.....转一下
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
郁闷!难道真的没办法解决了吗???
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
那楼上的你的代码里没有
rs.addnew
哦!!!就是加上了有必要判断
not rs.eof and rs.bof 吗???
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
哦!!我写错了应该是
rs而不是rs_2但程序还是添加不进去,而且我是在本地机上测试的
通过rs("str_user_account")="hekunharris"
都可以添加成功,但
rs("str_user_name")=str_user_name'变量
就不能哦!!
yymzzl 2004-04-30
  • 打赏
  • 举报
回复
sql="select * from [user]
rs.open sql,1,3
if not rs.eof and not rs.bof then
rs_2("str_user_account")=str_user_account
rs_2("str_user_code")=str_user_code

rs.update
response.write "更新成功!"
else
response.write "用户未发现!"
end if
rs.close
set rs=nothing
hhzh426 2004-04-30
  • 打赏
  • 举报
回复
rs.addnew
rs_2("str_user_account")="hekunharris"
rs_2("str_user_code")="123"
rs.update
其中rs_2是在哪儿定义的,是以什么方法打开的?

是access数据库吗?
如果是文件型数据库,还需要服务器上的文件系统中的写权限。
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
怎么了??各位老大,都不能解决吗??
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
意思是我执行完上面的更新数据库的代码后,再手工的打开数据库,里面没有新添加的记录,而手工的直接用rs("str_user_account")="hekunharris"就可以添加成功。数据库里就 有新的记录
anwell 2004-04-30
  • 打赏
  • 举报
回复
显示不出来是什么意思?
如果是新记录显示不出来。。但能插入进去。

试试这样
sql="select * from [user] order by id desc"
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
是添加新的记录
yymzzl 2004-04-30
  • 打赏
  • 举报
回复
是添加的新记录么?
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
肯定不行的,单引号’加在双引号的外面就成了注释了
skyboy0720 2004-04-30
  • 打赏
  • 举报
回复
rs_2("str_user_account")='"&str_user_account&"'
rs_2("str_user_code")='"&str_user_code&"'
hekunharris 2004-04-30
  • 打赏
  • 举报
回复
补充:
当然前面都设置了数据库连接的
set rs=server.creatobject("adodb.recordset")
和把conn.asp文件包含了的

28,390

社区成员

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

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