注册 登录
编程论坛 ASP技术论坛

郁闷啊、、我刚入手。asp无法连接到数据库

飞剑嗔 发布于 2010-09-24 10:10, 491 次点击
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>

<%
if request ("method")="value" then
set conn=server.createobject("adodb.connection")
conn.open"provider=microsoft.jet.oledb.4.0; data source=" & server.MapPath("link.mdb")
conn.execute "insert into link_aa (link_name,link_address,link_info) values('"&request("link_name")&"','"&request("link_address")&"','"&request("link_info")&"')"

%>
<SCRIPT LANGUAGE="JavaScript">

alert("成功")
</script>
<%
end if
%>


<table width="200" border="0" align="center">
  <tr>
    <th scope="row"><div align="right">网站名称</div></th>
    <td><form id="form2" name="form2" method="post" action="">
      <label>
      <input type="text" name="textfield" id="link_name" />
      </label>
    </form>    </td>
  </tr>
  <tr>
    <th scope="row"><div align="right">网站地址</div></th>
    <td><form id="form3" name="form3" method="post" action="index.asp">
      <label>
        <input name="link_address" type="text" id="link_address" />
        </label>
    </form>    </td>
  </tr>
  <tr>
    <th scope="row"><div align="right">网站描述</div></th>
    <td><form id="form4" name="form4" method="post" action="index.asp">
      <label>
        <input name="link_info" type="text" id="link_info" />
        <input name="method" type="hidden" value="save" />
        </label>
    </form>    </td>
  </tr>
  <tr>
    <th colspan="2" scope="row"><form id="form1" name="form1" method="post" action="index.asp">
      <label>
        <input type="submit" name="Submit" value="提交" />
        </label>
    </form>    </th>
  </tr>
</table>
<%
if request ("method")="value" then
conn.close
set conn=nothing
end if
%>
</body>
</html>
1 回复
#2
wangjy5002010-09-24 12:51
不是连接数据库的问题!
是你程序有问题。
一个form可解决的事。你用了4个
当然会有问题。

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>

<%
if request.form("method")="save" then
set conn=server.createobject("adodb.connection")
conn.open"provider=microsoft.jet.oledb.4.0; data source=" & server.MapPath("link.mdb")
conn.execute "insert into link_aa (link_name,link_address,link_info) values('"&request("link_name")&"','"&request("link_address")&"','"&request("link_info")&"')"

%>
<SCRIPT LANGUAGE="JavaScript">
alert("成功");
</script>
<%
end if
%>

<form id="form1" name="form1" method="post" action="index.asp">
<table width="200" border="0" align="center">
  <tr>
    <th scope="row"><div align="right">网站名称</div></th>
    <td>
      <label>
      <input type="text" name="textfield" id="link_name" />
      </label>
   </td>
  </tr>
  <tr>
    <th scope="row"><div align="right">网站地址</div></th>
    <td>
      <label>
        <input name="link_address" type="text" id="link_address" />
        </label>
    </td>
  </tr>
  <tr>
    <th scope="row"><div align="right">网站描述</div></th>
    <td>
      <label>
        <input name="link_info" type="text" id="link_info" />
        <input name="method" type="hidden" value="save" />
        </label>
   </td>
  </tr>
  <tr>
    <th colspan="2" scope="row">
      <label>
        <input type="submit" name="Submit" value="提交" />
        </label>
      </th>
  </tr>
</table> </form>

</body>
</html>
<%
conn.close
set conn=nothing
%>
1