100分求update用法

mysite365 2009-04-21 02:42:56
表tab

id aa bb cc dd
1 1 2 3 6
2 1 5 3 8
3 1 2 3 9
4 1 2 3 5

现在想使用update
把表中的aa=1 bb=2 cc=3 的记录

变为 aa=10 bb=20 cc=30

具体方法要怎么写?

我这样写没起作用:

conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1, bb=2,cc=3")

不知道错在哪里了。。
...全文
786 24 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
taochunsong 2009-04-22
  • 打赏
  • 举报
回复
conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 and bb=2 and cc=3")
lingyun410 2009-04-22
  • 打赏
  • 举报
回复
把表中的aa=1 bb=2 cc=3 的记录这是且的条件么?
如果是且的条件你二楼的做法应该可以完成你要的功能了。
madelaop5566 2009-04-22
  • 打赏
  • 举报
回复
. 阅
mysite365 2009-04-21
  • 打赏
  • 举报
回复
总结帖----2重方法:
1:
   
conn.execute("update Info set typeid_2="&shop_class3&", typeid="&shop_class2&",sortid="&shop_class1&" where typeid_2=0 and typeid=0 and sortid="&id&" ")

学到:conn.execute 不需要指针移动
2:

set rs= server.createobject ("adodb.recordset")
sql ="select * from Info where typeid_2="&id&" and typeid="&typeid&" and sortid="&sortid&" "
rs.open sql,conn,1,3 '加入这行
do while not rs.eof
rs("sortid")=shop_class1
rs("typeid")=shop_class2
rs("typeid_2")=shop_class3
rs.update
rs.movenext
loop
rs.close

完成,谢谢大家了
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 mysite365 的回复:]
set rs= server.createobject ("adodb.recordset")
sql ="select * from tab where aa=1 and bb=2 and cc=3"
rs.open sql,conn,1,3
do while not rs.eof
conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 and bb=2 and cc=3")
rs.movenext
loop


这样????
[/Quote]
有你这么用的嘛
用了conn.execute还用什么rs
用了RS才用do while not rs.eof
yaoho_11 2009-04-21
  • 打赏
  • 举报
回复
我试了下 没有问题啊
id aa bb cc dd
1 1 2 3 6
2 1 5 3 8
3 1 2 3 9
4 1 2 3 5

create table tab (
id int, aa int , bb int, cc int,dd int
)


select * from tab where aa=1 and bb=2 and cc=3

insert into tab values(1,1,2,3,6);
insert into tab values(2,1,5,3,8);
insert into tab values(3,1,2,3,9);
insert into tab values(4,1,2,3,5);

--update tab set aa=10,bb=20,cc=30 where aa=1 and bb=2 and cc=3

没发现问题
java code:
PreparedStatement pst = null;
String strSql = null;
strSql = "update tab set aa=10,bb=20,cc=30 where aa=1 and bb=2 and cc=3";
pst = conn.prepareStatement(strSql);
ret = pst.executeUpdate();
mysite365 2009-04-21
  • 打赏
  • 举报
回复
经过测试:
使用这样方法:
conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 and bb=2 and cc=3")
不需要
do while not rs.eof

rs.movenext
loop
mysite365 2009-04-21
  • 打赏
  • 举报
回复
set rs= server.createobject ("adodb.recordset")
sql ="select * from tab where aa=1 and bb=2 and cc=3"
rs.open sql,conn,1,3
do while not rs.eof
conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 and bb=2 and cc=3")
rs.movenext
loop


这样????
  • 打赏
  • 举报
回复
呵呵,LZ的的第一个是有问题的哦

那样只能更新一条
如果要更新多条得加do while not rs.eof

rs.movenext
loop
明珠佩佩 2009-04-21
  • 打赏
  • 举报
回复
1、数据库连接问题,这属于基础不扎实


set rs= server.createobject ("adodb.recordset")
sql ="select * from tab where aa=1 and bb=2 and cc=3"

rs.open sql,conn,1,3 加入这行

if rs.eof or rs.bof then
response.Write(" <script language='javascript'>alert(""出错!""); </script>")
else
rs("aa")=10
rs("bb")=20
rs("cc")=30
rs.update
rs.close


2、查询语句问题,建议你好好看看书再问


conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 and bb=2 and cc=3")
lzj34 2009-04-21
  • 打赏
  • 举报
回复
还有这种方法哪里错了。

set rs= server.createobject ("adodb.recordset")
sql ="select * from tab where aa=1 and bb=2 and cc=3"

rs.open sql,conn,1,3 加入这行
if rs.eof or rs.bof then
response.Write(" <script language='javascript'>alert(""出错!""); </script>")
else
rs("aa")=10
rs("bb")=20
rs("cc")=30
rs.update
rs.close
因为你的里面没有打开表如何进行更新呀
liooon 2009-04-21
  • 打赏
  • 举报
回复
set rs= server.createobject ("adodb.recordset")
sql ="select * from tab where aa=1 and bb=2 and cc=3"

rs.open sql,conn,1,3 加入这行

if rs.eof or rs.bof then
response.Write(" <script language='javascript'>alert(""出错!""); </script>")
else
rs("aa")=10
rs("bb")=20
rs("cc")=30
rs.update
rs.close
mysite365 2009-04-21
  • 打赏
  • 举报
回复
还有这种方法哪里错了。

set rs= server.createobject ("adodb.recordset")
sql ="select * from tab where aa=1 and bb=2 and cc=3"
if rs.eof or rs.bof then
response.Write(" <script language='javascript'>alert(""出错!""); </script>")
else
rs("aa")=10
rs("bb")=20
rs("cc")=30
rs.update
rs.close
mysite365 2009-04-21
  • 打赏
  • 举报
回复
conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 and bb=2 and cc=3")

这样感觉应该对了,但是这样做。记录没有变化。。意思是没有起作用。。。。。。。
sy_binbin 2009-04-21
  • 打赏
  • 举报
回复
假如条件aa=1,bb=2 ,cc=3同时相等的话,把条件用and链接起来就可以

如果不一定相等的话就要更新三次数据库
mysite365 2009-04-21
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sy_binbin 的回复:]
conn.execute("update tab set aa = 10 where aa =1")
conn.execute("update tab set bb= 20 where bb=2")
conn.execute("update tab set cc= 30 where cc=3")
[/Quote]

你这样不是把id=2 的a给替换了吗。。。。
sy_binbin 2009-04-21
  • 打赏
  • 举报
回复
conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 and bb=2 and cc=3")
  • 打赏
  • 举报
回复

conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 or bb=2 or cc=3")

还是?

conn.execute("update tab set aa=10, bb=20,cc=30 where aa=1 and bb=2 and cc=3")
zhuyongzhao 2009-04-21
  • 打赏
  • 举报
回复
conn.execute("update tab set aa = 10 where aa =1")
conn.execute("update tab set bb= 20 where bb=2")
conn.execute("update tab set cc= 30 where cc=3")
zhuyongzhao 2009-04-21
  • 打赏
  • 举报
回复
onn.execute("update tab set aa=10, bb=20,cc=30 where id=1")
加载更多回复(3)

28,409

社区成员

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

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