| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 636 人关注过本帖
标题:求助(一个让我头疼的判断语句)
只看楼主 加入收藏
xiaoguizi106
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2006-11-30
收藏
 问题点数:0 回复次数:7 
求助(一个让我头疼的判断语句)

请各位大虾帮忙看看
我想实现:查询数据库 如果有那么就将数据库的内容 部分字段更新
如果没有 就追加一条新纪录

为什么 每次运行只运行前半段 而不进行判断呢?
<!--#INCLUDE FILE="data1.asp" -->

<!--#INCLUDE FILE="html.asp" -->
<%
temp1=request("now_name")
set rs=server.CreateObject("adodb.recordset")
sql="selcet * from nowmaterial where now_name='"&temp1&"'"
rs.open sql,conn,1,3
if rs.recordcount>1 then


rs("now_name")=rs("now_name")
rs("type")=rs("type")
rs("now_spec")=rs("now_spec")
rs("now_model")=rs("now_model")
rs("now_amount")=request("now_amount")+rs("now_amount")
rs("unit")=rs("unit")
rs("now_price")=request("now_price")
rs("now_total")=request("now_price")*(request("now_amount")+rs("now_amount"))
rs("now_beizhu")=Server.HTMLEncode(request.Form("now_beizhu"))
rs("now_lbuyer")=request("now_lbuyer")
rs("last_indate")=request("last_indate")
rs("add")=request("add")
rs("now_manager")=rs("now_manager")
rs.update
rs.close
conn.close
set rs=nothing
response.write "<script language='javascript'>" & chr(13)
response.write "alert('库存更新成 功!');" & Chr(13)
response.write "window.document.location.href='nowmaterial_manage.asp';"&Chr(13)
response.write "</script>" & Chr(13)
Response.End

else


set rs=server.CreateObject("adodb.recordset")
sql="select * from nowmaterial"
rs.open sql,conn,1,3
rs.addnew
rs("now_name")=request("now_name")
rs("type")=request("type")
rs("now_spec")=request("now_spec")
rs("now_model")=request("now_model")
rs("now_amount")=request("now_amount")
rs("unit")=request("unit")
rs("now_price")=request("now_price")
rs("now_total")=request("now_amount")*request("now_price")
rs("now_beizhu")=Server.HTMLEncode(request.Form("now_beizhu"))
rs("now_lbuyer")=request("now_lbuyer")
rs("last_indate")=request("last_indate")
rs("add")=request("add")
rs("now_manager")=request("now_manager")
rs.update
rs.close
conn.close
set rs=nothing
response.write "<script language='javascript'>" & chr(13)
response.write "alert('该物资入库登记成功!');" & Chr(13)
response.write "window.document.location.href='nowmaterial_manage.asp';"&Chr(13)
response.write "</script>" & Chr(13)
Response.End

%>
<%end if%>


搜索更多相关主题的帖子: 语句 头疼 判断 
2006-11-30 16:05
caor1987
Rank: 1
等 级:新手上路
帖 子:228
专家分:0
注 册:2006-10-15
收藏
得分:0 
我觉得像rs("now_name")=rs("now_name")这样的语句是多余的,没必要写。
还有我觉得你的判断语句有点问题,你自己换个其他方式的判断试下。
例如把rs.recordcount>1换成not rs.eof
2006-11-30 16:23
xiaoguizi106
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2006-11-30
收藏
得分:0 
谢谢大虾caor1987提点  你QQ号是多少?
2006-11-30 16:51
seal520_2008
Rank: 1
等 级:新手上路
帖 子:239
专家分:0
注 册:2006-6-13
收藏
得分:0 

if not rs.eof then
rs("now_name")=request("now_name")
.
.
.
rs.update
else
rs.addnew
rs("now_name")=request("now_name")
.
.
.
rs.update
end if

这样简单的判断下就可以了

[此贴子已经被作者于2006-11-30 17:14:50编辑过]


每晚0:00上线 msn:seal520_2008@ myblog:http://seal.
2006-11-30 17:11
zsf2006
Rank: 1
来 自:博客园
等 级:新手上路
威 望:1
帖 子:315
专家分:0
注 册:2006-6-3
收藏
得分:0 
就这么简单...

光临我的博客:http://
2006-11-30 18:31
jimmy_wang
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2006-10-10
收藏
得分:0 
if rs.recordcount <> 1 then
rs.addnew
else
rs("now_name")=request("now_name")
.
.
.
rs.update
end if
2006-12-01 09:11
craft001wen
Rank: 2
等 级:论坛游民
帖 子:242
专家分:62
注 册:2006-5-4
收藏
得分:0 
晕,代码有点乱
帮你简化一下
<%
temp1=request("now_name")
set rs=server.CreateObject("adodb.recordset")
sql="selcet * from nowmaterial where now_name='"&temp1&"'"
rs.open sql,conn,1,3
if not rs.eof and not rs.bof then
call aa()
response.write "<script language='javascript'>" & chr(13)
response.write "alert('库存更新成 功!');" & Chr(13)
response.write "window.document.location.href='nowmaterial_manage.asp';"&Chr(13)
response.write "</script>" & Chr(13)
Response.End
else
rs.addnew()
call aa()
response.write "<script language='javascript'>" & chr(13)
response.write "alert('该物资入库登记成功!');" & Chr(13)
response.write "window.document.location.href='nowmaterial_manage.asp';"&Chr(13)
response.write "</script>" & Chr(13)
Response.End
end if
%>
<%

sub aa()
rs("now_name")=request("now_name")
rs("type")=request("type")
rs("now_spec")=request("now_spec")
rs("now_model")=request("now_model")
rs("now_amount")=request("now_amount")
rs("unit")=request("unit")
rs("now_price")=request("now_price")
rs("now_total")=request("now_amount")*request("now_price")
rs("now_beizhu")=Server.HTMLEncode(request.Form("now_beizhu"))
rs("now_lbuyer")=request("now_lbuyer")
rs("last_indate")=request("last_indate")
rs("add")=request("add")
rs("now_manager")=request("now_manager")
rs.update
rs.close
conn.close
set rs=nothing
end sub
%>

2006-12-01 14:49
zhangling
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-25
收藏
得分:0 
楼上的代码很简洁啊,确实很好
2006-12-02 10:43
快速回复:求助(一个让我头疼的判断语句)
数据加载中...
 
   



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

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