| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1189 人关注过本帖
标题:[已解决]rs.update的奇怪问题,大家来看看,问题出在哪儿
取消只看楼主 加入收藏
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
 问题点数:0 回复次数:8 
[已解决]rs.update的奇怪问题,大家来看看,问题出在哪儿
是这样的,我用session保存了待更改的产品id,当我修改某产品图片路径时,用了如下语句:
====================
Dim rs,strSql
Set rs = Server.CreateObject("ADODB.Recordset")
strSql = "select imgpath from product where id=" & Session("id") 'imgpath为access数据库中保存的图片路径
rs.open strSql,G_CONN,1,3 '这句有的,不好意思,漏打上去了刚才。
rs("imgpath")="一个新的路径字符串"
rs.update
rs.close
Set rs = Nothing
Session("id")=""
====================
可是这么写总是变成新添加一条记录(我这里并没有写rs.addnew)而不是更改原记录。
也尝试过改为:
1,"insert into product(imgpath) values('新路径') where id=" & Session("id")
2, "update product set imgpath ='新路进’where id=" & Session("id")
但结果和前面一样变成新建了一条记录,并把结果填写到对应的imgpath字段内。
高手来帮我看一下吧,我懊恼了N久,还是没发现原因所在。
谢谢大家!

[此贴子已经被作者于2007-8-21 10:18:56编辑过]

搜索更多相关主题的帖子: update 数据库 Set 
2007-08-20 15:28
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
得分:0 
有这句的,呵呵,不好意思,刚才漏了。继续想听听高手的意见,问题的原因不知道在哪儿。。。
G_CONN.Execute +上面的语句1或2我都试过,但是出现了同样的问题。
我测试过,该页面传递的Session("id")完全正确。但是最后为什么变成添加新纪录了而不是更改原记录的字段?

[此贴子已经被作者于2007-8-20 15:41:14编辑过]


2007-08-20 15:37
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
得分:0 
以下是引用ayue222在2007-8-20 15:44:34的发言:
id="&Cint(Session("id"))

谢谢楼上那位朋友,我这样试了一下,还是原来的状况,呜呜


Session传过来的id是没有问题的。我用Response.write测试过,正确的。

[此贴子已经被作者于2007-8-20 15:51:06编辑过]


2007-08-20 15:50
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
得分:0 

肯定有记录的,还是找不到问题的根源。。。。


2007-08-20 16:12
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
得分:0 
以下是引用madpbpl在2007-8-20 16:57:40的发言:
response.write session("id")
你看看这个值是不是你要更新对应的id,感觉问题应该出在这里

我用过这句语句来测试,session 传值正常!


2007-08-20 17:02
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
得分:0 

调用的地方是:<iframe src='admin_upload.asp?action=modify'></iframe>

amdin_upload.asp
<%
Response.expires=-1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","no-store"
%>
<!--#include file="inc/conn.asp"-->
<!--#include file="inc/function.asp"-->
<!--#include file="inc/UpLoadClass.asp"--> ’此处运用风声无组件上传图片
<%
If checkAdminLogin() = False Then '检验是否登录
Response.Redirect "admin_login.htm"
End If
Server.ScriptTimeOut=5000
Dim request2,rs,strSql,strAction
Set request2=New UpLoadClass '这个是风声上传里的
request2.Charset="utf-8"
request2.Open()
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload Image</title>
<style type="text/css">body,form{margin:0;padding:0;background:#C6EBDE}#strPhoto{width:300px;}Input{font-family:"Verdana, Arial";font-size:9pt;color:#555555;background-color:#fefefe;border:1px solid #555555}</style>
</head>
<body>
<!--下面的表单用于提交图片-->
<form name="upimg" method="post" action="admin_upload.asp?toup=1" enctype="multipart/form-data"><input name="strPhoto" type="file" id="strPhoto" /> <input type="submit" name="upload" value="upload" /></form>
<%
’以下程序分为两部分,modify用于修改图片的地址(问题出在这个模块),而main则是用于添加新商品的图片
strAction = Trim(Request.QueryString("action"))
If strAction = "modify" Then
Call modify() '修改商品图片
Else Call main() '添加新商品
End If

Sub main()
If Session("imgid") = "" Then
Response.Write "<div style='background:#999999;width:300px;height:14px;font:bold 10px Verdana;color:#FFFF00;' id='noticeimg'>Only images [jpg/gif] &lt;200K are allowed!</div>"
If Request.QueryString("toup") = 1 Then
Set rs=Server.CreateObject("ADODB.Recordset")
strSql="select * from product"
rs.open strSql,G_CONN,1,3
rs.addnew
rs("imgpath")=request2.SavePath&request2.Form("strPhoto")
rs.update
'Aspjpeg组件生成两个尺寸的缩略图
Set Jpeg=Server.CreateObject("Persits.Jpeg")
Path = Server.MapPath(rs("imgpath"))
Jpeg.Open Path
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
Jpeg.Quality = 90
Jpeg.Save Server.MapPath("upload\middle")&Mid(rs("imgpath"),7)
Jpeg.Width = Jpeg.OriginalWidth / 2 '在上一次计算的基础上
Jpeg.Height = Jpeg.OriginalHeight / 2
Jpeg.Save Server.MapPath("upload/small")&Mid(rs("imgpath"),7)'正反斜杠都行
Set Jpeg = Nothing
Session("imgid") = rs("id") '保存上传图片对应的id
rs.Close
Set rs = Nothing
Response.Write "<script>document.upimg.style.visibility='hidden';noticeimg.innerHTML='Image uploaded.'</script>"
End If
Else
Response.Write "<script>document.upimg.style.visibility='hidden'</script><div style='background:#999999;width:300px;height:14px;font:bold 10px Verdana;color:#FFFF00;'>Image uploaded.</div></body></html>"
End If
End Sub

Sub modify()
If Session("delimg") = "" Then
Response.Write "<div style='background:#999999;width:300px;height:14px;font:bold 10px Verdana;color:#FFFF00;' id='noticeimg'>No image need to be updated!</div>"
Response.End
Else
If Request.QueryString("toup") = 1 Then
Dim rs,strSql,temp
strSql="update product set imgpath ='"&request2.SavePath&request2.Form("strPhoto")&"' where id="&Session("delimgid")
G_CONN.Execute strSql
Set rs = Server.CreateObject("ADODB.Recordset")
rs.open "select imgpath from product where id=" & Session("delimgid"),G_CONN,1,1
temp = rs("imgpath")
Set Jpeg=Server.CreateObject("Persits.Jpeg")
Path = Server.MapPath(temp)
Jpeg.Open Path
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
Jpeg.Quality = 90
Jpeg.Save Server.MapPath("upload\middle")&Mid(temp,7)
Jpeg.Width = Jpeg.OriginalWidth / 2
Jpeg.Height = Jpeg.OriginalHeight / 2
Jpeg.Save Server.MapPath("upload\small")&Mid(temp,7)
Set Jpeg = Nothing
rs.Close
Set rs = Nothing
Response.Write "<script>document.upimg.style.visibility='hidden';noticeimg.innerHTML='Image uploaded.'</script>"
End If
End If
End Sub
%>

由于刚学asp不久,水平挺菜的。。所以不足之处还有很多,望高手能够多多指出不足,好让小弟改进,衷心的谢谢大家!

[此贴子已经被作者于2007-8-20 17:21:55编辑过]


2007-08-20 17:09
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
得分:0 
以下是引用阳光白雪在2007-8-20 17:17:08的发言:
strAction = Trim(Request.QueryString("action"))
If strAction = "modify" Then
response.write("修改")
response.end()
Call modify() '修改商品图片
Else
response.write("新增")
response.end()
Call main() '添加新商品
End If

用这个试下执行了哪个动作,貌似 strAction 有问题

谢谢阳光白雪,刚才试过了这一段和自己的程序,都显示的是“修改”,说明strAction是没有问题的。
继续探索中。。。。

[此贴子已经被作者于2007-8-20 17:26:33编辑过]


2007-08-20 17:24
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
得分:0 
谢谢大家的帮助,刚才测试下来,发现我的session("delimgid")肯定有问题,不知道我前面的哪段程序将他清空了Session("delimgid")=""。详细情况我要再好好测试一下,等问题解决后再来谢谢大家!

[此贴子已经被作者于2007-8-20 17:35:17编辑过]



2007-08-20 17:35
slfyeye
Rank: 1
来 自:上海
等 级:新手上路
威 望:1
帖 子:163
专家分:0
注 册:2006-3-5
收藏
得分:0 

已经解决,谢谢大家的帮助!昨天错误出在提交表单是漏了action=modify,导致提交后变成新增图片了。。。。看来编程需要相当细心啊。


2007-08-21 10:18
快速回复:[已解决]rs.update的奇怪问题,大家来看看,问题出在哪儿
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013512 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved