ASP数据库中添加数据
我做了一个添加电脑的ASP页面,一个是index.asp,一个是tianjia_conn.asp,现在已经连接数据库,也可以向数据库中添加数据,但是关键是现在可以添加重复...
我做了一个添加电脑的ASP页面,一个是index.asp,一个是tianjia_conn.asp,现在已经连接数据库,也可以向数据库中添加数据,但是关键是现在可以添加重复的数据,一条命令可以添加几十次上百次,我本来想法是添加数据之前查询一下数据库中是否有这条数据,如果有就跳出窗口说“数据已经存在”,如果没有这条数据则添加,请问怎么实现,下面是代码index.asp
<form name="form1" method="post" action="tianjia.asp" onsubmit="return checkform();">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td width="35%" align="right">IP:</td>
<td width="16%" align="left"><input name="IP" type="text" id="IP"></td>
<td width="70" align="right"> CPU: </td>
<td align="left"><input name="cpu" type="text" id="cpu" /></td>
</tr>
<tr align="center">
<td width="35%" align="right">MAD地址:</td>
<td align="left"><input name="MAC" type="text" id="MAC"></td>
<td width="70" align="right">内存: </td>
<td align="left"><input name="nc" type="text" id="nc" /></td>
</tr>
<tr align="center">
<td width="35%" align="right">使用人:</td>
<td align="left"><input name="USER" type="text" id="USER"></td>
<td width="70" align="right">硬盘: </td>
<td align="left"><input name="yp" type="text" id="yp" /></td>
</tr>
<tr align="center">
<td width="35%" align="right">主机名:</td>
<td align="left"><input name="MINGZI" type="text" id="MINGZI"></td>
<td width="70" align="right">品牌:</td>
<td align="left"><input name="pp" type="text" id="pp" /></td>
</tr>
<tr align="center">
<td width="35%" align="right">部门:</td>
<td align="left"><input name="BUMEN" type="text" id="BUMEN"></td>
<td width="70" rowspan="2" align="right">备注: </td>
<td rowspan="2" align="left"><textarea name="bz" id="bz"></textarea></td>
</tr>
<tr align="center">
<td align="right">是否上网:</td>
<td align="left"><input name="sfsw" type="text" id="sfsw" value="" /></td>
</tr>
<tr align="center">
<td height="50" colspan="4" align="center"><input type="submit" name="Submit" value="提交"> </td>
</tr>
</table>
</form>
下面是tianjia.asp
<%
IP=request.form("IP") MAC=request.form("MAC")
USER=request.form("USER")
MINGZI=request.form("MINGZI")
BUMEN=request.form("BUMEN")
sfsw=request.form("sfsw")
cpu=request.form("cpu")
nc=request.form("nc")
yp=request.form("yp")
pp=request.form("pp")
bz=request.form("bz")
dim sql,rs
set rs=server.createobject("adodb.recordset")
sql="select * from us"
rs.open sql,conn,1,3
rs.addnew()
rs("IP")=ip
rs("MAC")=mac
rs("USER")=user
rs("MINGZI")=mingzi
rs("BUMEN")=bumen
rs("sfsw")=sfsw
rs("cpu")=cpu
rs("nc")=nc
rs("yp")=yp
rs("pp")=pp
rs("bz")=bz
rs.update
response.write("<p align='center'><font color=red>添加成功!请返回</font></p>")
rs.close
set rs = nothing
conn.close
set conn= nothing
%>
添加数据之前怎么实现查询数据库中是否有数据 展开
<form name="form1" method="post" action="tianjia.asp" onsubmit="return checkform();">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<td width="35%" align="right">IP:</td>
<td width="16%" align="left"><input name="IP" type="text" id="IP"></td>
<td width="70" align="right"> CPU: </td>
<td align="left"><input name="cpu" type="text" id="cpu" /></td>
</tr>
<tr align="center">
<td width="35%" align="right">MAD地址:</td>
<td align="left"><input name="MAC" type="text" id="MAC"></td>
<td width="70" align="right">内存: </td>
<td align="left"><input name="nc" type="text" id="nc" /></td>
</tr>
<tr align="center">
<td width="35%" align="right">使用人:</td>
<td align="left"><input name="USER" type="text" id="USER"></td>
<td width="70" align="right">硬盘: </td>
<td align="left"><input name="yp" type="text" id="yp" /></td>
</tr>
<tr align="center">
<td width="35%" align="right">主机名:</td>
<td align="left"><input name="MINGZI" type="text" id="MINGZI"></td>
<td width="70" align="right">品牌:</td>
<td align="left"><input name="pp" type="text" id="pp" /></td>
</tr>
<tr align="center">
<td width="35%" align="right">部门:</td>
<td align="left"><input name="BUMEN" type="text" id="BUMEN"></td>
<td width="70" rowspan="2" align="right">备注: </td>
<td rowspan="2" align="left"><textarea name="bz" id="bz"></textarea></td>
</tr>
<tr align="center">
<td align="right">是否上网:</td>
<td align="left"><input name="sfsw" type="text" id="sfsw" value="" /></td>
</tr>
<tr align="center">
<td height="50" colspan="4" align="center"><input type="submit" name="Submit" value="提交"> </td>
</tr>
</table>
</form>
下面是tianjia.asp
<%
IP=request.form("IP") MAC=request.form("MAC")
USER=request.form("USER")
MINGZI=request.form("MINGZI")
BUMEN=request.form("BUMEN")
sfsw=request.form("sfsw")
cpu=request.form("cpu")
nc=request.form("nc")
yp=request.form("yp")
pp=request.form("pp")
bz=request.form("bz")
dim sql,rs
set rs=server.createobject("adodb.recordset")
sql="select * from us"
rs.open sql,conn,1,3
rs.addnew()
rs("IP")=ip
rs("MAC")=mac
rs("USER")=user
rs("MINGZI")=mingzi
rs("BUMEN")=bumen
rs("sfsw")=sfsw
rs("cpu")=cpu
rs("nc")=nc
rs("yp")=yp
rs("pp")=pp
rs("bz")=bz
rs.update
response.write("<p align='center'><font color=red>添加成功!请返回</font></p>")
rs.close
set rs = nothing
conn.close
set conn= nothing
%>
添加数据之前怎么实现查询数据库中是否有数据 展开
4个回答
展开全部
<%
IP=request.form("IP") MAC=request.form("MAC")
USER=request.form("USER")
MINGZI=request.form("MINGZI")
BUMEN=request.form("BUMEN")
sfsw=request.form("sfsw")
cpu=request.form("cpu")
nc=request.form("nc")
yp=request.form("yp")
pp=request.form("pp")
bz=request.form("凯段bz")
dim sql,rs
set rs=server.createobject("adodb.recordset")
sql="select * from us where mac='"&mac&"'" '这里我用MAC来判断是否存在,当然你可以改成其它的
rs.open sql,conn,1,3
if not rs.eof then
response.write "该MAC地址在数据库中已经存在"
response.end
end if
rs.addnew()
rs("IP")=ip
rs("MAC")=mac
rs("USER")=user
rs("MINGZI")=mingzi
rs("BUMEN")=bumen
rs("sfsw")=sfsw
rs("cpu")=cpu
rs("nc")=nc
rs("yp")=yp
rs("pp"拦锋)=pp
rs("bz")=bz
rs.update
response.write("<p align='center'><font color=red>简孙晌添加成功!请返回</font></p>")
rs.close
set rs = nothing
conn.close
set conn= nothing
%>
IP=request.form("IP") MAC=request.form("MAC")
USER=request.form("USER")
MINGZI=request.form("MINGZI")
BUMEN=request.form("BUMEN")
sfsw=request.form("sfsw")
cpu=request.form("cpu")
nc=request.form("nc")
yp=request.form("yp")
pp=request.form("pp")
bz=request.form("凯段bz")
dim sql,rs
set rs=server.createobject("adodb.recordset")
sql="select * from us where mac='"&mac&"'" '这里我用MAC来判断是否存在,当然你可以改成其它的
rs.open sql,conn,1,3
if not rs.eof then
response.write "该MAC地址在数据库中已经存在"
response.end
end if
rs.addnew()
rs("IP")=ip
rs("MAC")=mac
rs("USER")=user
rs("MINGZI")=mingzi
rs("BUMEN")=bumen
rs("sfsw")=sfsw
rs("cpu")=cpu
rs("nc")=nc
rs("yp")=yp
rs("pp"拦锋)=pp
rs("bz")=bz
rs.update
response.write("<p align='center'><font color=red>简孙晌添加成功!请返回</font></p>")
rs.close
set rs = nothing
conn.close
set conn= nothing
%>
展开全部
就是在插入春闷茄钱先查询一遍,如果有就提示重复。
dim sql,rs
set rs=server.createobject("adodb.recordset")
sql="select * from us where MAC='"扒察&MAC&"'罩滚" '这里我用MAC来判断是否存在,当然你可以改成其它的
rs.open sql,conn,1,3
if not rs.eof then
response.write "该MAC地址在数据库中已经存在"
response.end
end if
dim sql,rs
set rs=server.createobject("adodb.recordset")
sql="select * from us where MAC='"扒察&MAC&"'罩滚" '这里我用MAC来判断是否存在,当然你可以改成其它的
rs.open sql,conn,1,3
if not rs.eof then
response.write "该MAC地址在数据库中已经存在"
response.end
end if
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你添物桥加数据 又不需要返回值!你写返樱得漏蚂丛麻烦了 可以用<%
set rs=conn.execute("Select count(*) as num form us where ip="&ip)
If rs.eof then
conn.execute("Insert into us ('字段','字段') values (后面是值)")
else
Response.write "false"
end if
%>
set rs=conn.execute("Select count(*) as num form us where ip="&ip)
If rs.eof then
conn.execute("Insert into us ('字段','字段') values (后面是值)")
else
Response.write "false"
end if
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
一楼很详细了……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询