28,406
社区成员
发帖
与我相关
我的任务
分享<%
'如果是表单提交过来,则先获取要更新的数据
action =Trim(request("action"))
bookname =Trim(request.Form("bookname"))
huiyuanjia =Trim(request.Form("huiyuanjia"))
isbn =Trim(request.Form("isbn"))
bookchuban =Trim(request.Form("bookchuban"))
'action=save则开始下面操作
if request("action")="save" then
'判断这四项是否为空,为空则返回填写完整。可按需求来是否必填
if bookname="" or huiyuanjia="" or isbn="" or bookchuban="" then
response.Write "<script>alert('四项不能为空,请填写完整!');history.go(-1);</"&"script>"
response.End()
end if
'判断表Purchaseprice里面PurchaseName字段是否已存在,不能重复插入!
if conn.execute("select count(*) from Purchaseprice where PurchaseName='"&bookname&"'")(0)>0 then
response.Write "<script>alert('该数据已存在,不需重复添加!');history.go(-1);</"&"script>"
response.End()
end if
'如果满足了上述要求,则开始添加数据
set rs=server.CreateObject("adodb.recordset")
sql="select top 1 * from Purchaseprice" '查询第一条通过if not (rs.bof or rs.eof) then 判断是否可以存在,不存在则在这个位置添加新的记录,top 1 * 主要是为了省资源
rs.open sql,conn,1,3
if not (rs.bof or rs.eof) then
rs.addnew '开始添加
rs("PurchaseName") =bookname
rs("PurchaseRetail") =huiyuanjia
rs("PurchaseSpecifications")=isbn
rs("PurchaseUnits") =bookchuban
rs.update '更新记录
end if
response.Write "添加成功!"
end if
rs.close
set rs=nothing
%>