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

求助,在网上下了个源码,有个部分总出错,请帮忙看看

发布于 2010-04-29 21:46, 462 次点击
<%
Dim Action,User,id
Action=request.QueryString("Action")
%>
<html>
<head>

<link href="style.css" rel="stylesheet" type="text/css">
<title>修改资料<%=Jinwebname%></title>
</head>
<body>
<%
Select Case Action
Case "Edit"
%>
<TABLE width=805 border=0 align="center" cellPadding=1 cellSpacing=1 bgColor=#CCCCFF>
  <TBODY>
    <TR>
      <TD width="663" align=middle bgColor=#ffffff><TABLE cellSpacing=1 cellPadding=0 width=689 border=0>
          <TBODY>
            <TR bgcolor="#CCCCFF">
              <TD width="25%" height=20><div align="center"><%
              TrueName=trim(request("TrueName"))
              Set rs=Server.CreateObject("Adodb.Recordset")
              rs.Open "Select * From Collection Where TrueName='"&TrueName&"'",Conn,1,1
              %><a href="Del.asp?TrueName=<% =trim(rs("TrueName")) %>" class="mnu" title="删除该记录!"><font color="#FF0000">删除该记录</font></a></div></TD>
              <TD>
                <div align="center">修改资料</div></TD>
              <TD width="25%"><div align="center"><a href="Index.asp" Class="mnu">返回首页</a></div></TD>
            </TR>
            <TR>
              <TD colspan="3" align=middle class=blue6><form method="post" action="Edit.asp?Action=Save&id=<%=trim(request("id"))%>" name="From">
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="28%" height="25"><font color="#999999">姓名:</font><font color="#FF0000">
                        <% =trim(rs("TrueName")) %>
                        </font></td>
                      <td><font color="#999999">性别:</font><%
                          Sex=trim(rs("Sex"))
                          If Sex=0 Then
                          %><input type="radio" name="Sex" value="0" checked>男<input type="radio" name="Sex" value="1">女<font color="#FF3333">*</font>
                        <% Else %>
                        <input type="radio" name="Sex" value="0">男<input name="Sex" type="radio" value="1" checked>女<font color="#FF3333">*</font>
                        <%End If%>
                      </td>
                      <td width="25%"><font color="#999999">分类:
                        <%
                      UserName=Request.Cookies("UserName")
                      Set Fl=Server.CreateObject("Adodb.Recordset")
                      Fl.Open "Select * From Class Where UserName='"&UserName&"'",Conn,1,1
                      %>
                        <select name="ClassName" id="ClassName">
                          <option value="<% =trim(rs("ClassName")) %>"><% =trim(rs("ClassName")) %></option><%
                      Do While Not Fl.EOF
                      %>
                          <option value="<% =trim(Fl("ClassName")) %>"><% =trim(Fl("ClassName")) %></option><%
                      Fl.MoveNext
                      Loop
                      Fl.Close
                      Set Fl=Nothing
                      %>
                        </select>
                        </font></td>
                      <td width="28%"><font color="#999999">QQ:
                        <input name="WebName" type="text" Class="fr2" id="WebName" value="<% =trim(rs("WebName")) %>" size="20">
                        </font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="33%" height="25"><font color="#999999">国家:<input name="TrueNameCountry" type="text" Class="fr2" id="TrueNameCountry" value="<% =trim(rs("TrueNameCountry")) %>" size="20">
                        </font></td>
                      <td><font color="#999999">城市:<input name="TrueNameCity" type="text" Class="fr2" id="TrueNameCity" value="<% =trim(rs("TrueNameCity")) %>" size="20">
                        </font></td>
                      <td width="33%"><font color="#999999">生日:</font><font color="#999999"><input name="TrueNameYear" type="text" Class="fr2" id="TrueNameYear" value="<% =trim(rs("TrueNameYear")) %>" size="4">年
                             <input name="TrueNameMoon" type="text" Class="fr2" id="TrueNameMoon" value="<% =trim(rs("TrueNameMoon")) %>" size="2">月<input name="TrueNameDay" type="text" Class="fr2" id="TrueNameDay" value="<% =trim(rs("TrueNameDay")) %>" size="2">日</font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="25"><font color="#999999">住址:<input name="Address" type="text" Class="fr2" id="Address" value="<% =trim(rs("Address")) %>" size="60">
                        </font></td>
                      <td width="33%"><font color="#999999">邮编:<input name="PostCode" type="text" Class="fr2" id="PostCode" value="<% =trim(rs("PostCode")) %>" size="20">
                        </font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="33%" height="25"><font color="#999999">电话:<input name="TrueNameTel" type="text" Class="fr2" id="TrueNameTel" value="<% =trim(rs("TrueNameTel")) %>" size="20">
                        </font></td>
                      <td><font color="#999999">传真:<input name="TrueNameFax" type="text" Class="fr2" id="TrueNameFax" value="<% =trim(rs("TrueNameFax")) %>" size="20">
                        </font></td>
                      <td width="33%"><font color="#999999">手机:<input name="TrueNameMobile" type="text" Class="fr2" id="TrueNameMobile" value="<% =trim(rs("TrueNameMobile")) %>" size="20">
                        </font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="50%" height="25"><font color="#999999">电子邮件:<input name="Email" type="text" Class="fr2" id="Email" value="<% =trim(rs("Email")) %>" size="30">
                        </font></td>
                      <td><font color="#999999">个人网址:<input name="HomePage" type="text" Class="fr2" id="HomePage" value="<% =trim(rs("HomePage")) %>" size="30">
                        </font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="25"><font color="#999999">公司:<input name="IncName" type="text" Class="fr2" id="IncName" value="<% =trim(rs("IncName")) %>" size="60"></font></td>
                      <td width="33%"><font color="#999999">职位:<input name="IncJob" type="text" Class="fr2" id="IncJob" value="<% =trim(rs("IncJob")) %>" size="20"></font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="33%" height="25"><font color="#999999">电话:<input name="IncTel" type="text" Class="fr2" id="IncTel" value="<% =trim(rs("IncTel")) %>" size="20"></font></td>
                      <td><font color="#999999">传真:<input name="IncFax" type="text" Class="fr2" id="IncFax" value="<% =trim(rs("IncFax")) %>" size="20"></font></td>
                      <td width="33%"><font color="#999999">邮编:<input name="IncPostCode" type="text" Class="fr2" id="IncPostCode" value="<% =trim(rs("IncPostCode")) %>" size="20"></font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="33%" height="25"><font color="#999999">城市:<input name="IncCity" type="text" Class="fr2" id="IncCity" value="<% =trim(rs("IncCity")) %>" size="20"></font></td>
                      <td><font color="#999999">地址:<input name="IncAddress" type="text" Class="fr2" id="IncAddress" value="<% =trim(rs("IncAddress")) %>" size="60"></font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="50%" height="25"><font color="#999999">电子邮件:<input name="IncEmail" type="text" Class="fr2" id="IncEmail" value="<% =trim(rs("IncEmail")) %>" size="30"></font></td>
                      <td><font color="#999999">公司网址:<input name="IncHomePage" type="text" Class="fr2" id="IncHomePage" value="<% =trim(rs("IncHomePage")) %>" size="30"></font></td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="25"><font color="#999999">备注:</font><textarea name="bz" cols="70" rows="10" id="bz"><% =trim(rs("bz")) %></textarea>
                      </td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td>&nbsp;</td>
                    </tr>
                  </table>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td><div align="center">
                          <input name="Submit1" type="submit" id="Submit1" value="提交" Class="fr2">
                          <input type="reset" name="Submit" value="重置" Class="fr2">
                        </div></td>
                    </tr>
                  </table>
                </form></TD>
            </TR>
          </TBODY>
      </TABLE></TD>
    </TR>
  </TBODY>
</TABLE>
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><div align="center"></div></td>
  </tr>
</table>
<% Case "Save" %>
<TABLE width=600 border=0 align="center" cellPadding=1 cellSpacing=1 bgColor=#CCCCFF>
  <TBODY>
    <TR>
      <TD align=middle bgColor=#ffffff> <TABLE cellSpacing=1 cellPadding=0 width=600 border=0>
          <TBODY>
            <TR bgcolor="#CCCCFF">
              <TD width="25%" height=20>&nbsp;</TD>
              <TD> <div align="center">修改资料</div></TD>
              <TD width="25%">&nbsp; </TD>
            </TR>
            <TR>
              <TD colspan="3" align=middle class=blue6><%call saveuser()%></TD>
            </TR>
          </TBODY>
        </TABLE></TD>
    </TR>
  </TBODY>
</TABLE>
<table width="231" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="229"><div align="center">
        Copyright&copy; <%=Jinwebcopyright%> Inc.</div></td>  
  </tr>
</table>
<% End Select %>
</body>
</html>
<%
sub saveuser()
id=trim(request("id"))
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from Collection where id=id",conn,1,3《==个人感觉是这有问题
rs("Sex")=trim(request("Sex"))
rs("ClassName")=trim(request("ClassName"))
rs("WebName")=trim(request("WebName"))
rs("TrueNameYear")=trim(request("TrueNameYear"))
rs("TrueNameMoon")=trim(request("TrueNameMoon"))
rs("TrueNameDay")=trim(request("TrueNameDay"))
rs("TrueNameTel")=trim(request("TrueNameTel"))
rs("TrueNameFax")=trim(request("TrueNameFax"))
rs("TrueNameMobile")=trim(request("TrueNameMobile"))
rs("TrueNameCountry")=trim(request("TrueNameCountry"))
rs("TrueNameCity")=trim(request("TrueNameCity"))
rs("Address")=trim(request("Address"))
rs("PostCode")=trim(request("PostCode"))
rs("Email")=trim(request("Email"))
rs("HomePage")=trim(request("HomePage"))
rs("bz")=trim(request("bz"))
rs.update
rs.close
set rs=nothing
response.Write "<table width=90% border=0 align=center cellpadding=0 cellspacing=0><tr><td height=80><font color=#cb6f00>  修改成功</font><br>"
response.Write "<a href=index.asp Class='mnu'>返回首页</a></td></tr></table></td></tr></table>"
end sub
%>

以上是 edit.asp 的代码,其中出错部分是:
ASP服务器发现运行时错误:
错 误 码:0x80040E2F
错误代码:rs.update
错误描述:[Microsoft][ODBC Microsoft Access Driver] 由于将在索引、 主关键字、或关系中创建重复的值,请求对表的改变没有成功。 改变该字段中的或包含重复数据的字段中的数据,删除索引或重新定义索引以允许重复的值并再试一次。
文件名称:f:\资料\通讯录\txl20100420\Edit.asp
所在行号:216

小白一个请大家帮忙看看该如何修改,整迷糊了。。。

还有我是用asp.studio运行asp文件的


[ 本帖最后由 siling00 于 2010-4-29 21:47 编辑 ]
3 回复
#2
gupiao1752010-04-29 22:22
rs.open "select * from Collection where id=id",conn,1,3
改为rs.open "select * from Collection where id="&id,conn,1,3 '如果id是数字型的

另外确保数据库里的字段和这里保存的字段是否都对应,都有相对应的字段存在吗?字段名称是否都一样,!
rs("Sex")=trim(request("Sex"))'数据库里必须要有Sex这个字段,数据格式必须符合对应类型,下面同理!
rs("ClassName")=trim(request("ClassName"))
rs("WebName")=trim(request("WebName"))
rs("TrueNameYear")=trim(request("TrueNameYear"))
rs("TrueNameMoon")=trim(request("TrueNameMoon"))
rs("TrueNameDay")=trim(request("TrueNameDay"))
rs("TrueNameTel")=trim(request("TrueNameTel"))
rs("TrueNameFax")=trim(request("TrueNameFax"))
rs("TrueNameMobile")=trim(request("TrueNameMobile"))
rs("TrueNameCountry")=trim(request("TrueNameCountry"))
rs("TrueNameCity")=trim(request("TrueNameCity"))
rs("Address")=trim(request("Address"))
rs("PostCode")=trim(request("PostCode"))
rs("Email")=trim(request("Email"))
rs("HomePage")=trim(request("HomePage"))
rs("bz")=trim(request("bz"))
#3
zzy_4202010-04-29 22:52
rs.open "select * from Collection where id='" & id & "'",conn,1,3
rs("Sex")=trim(request("Sex"))
rs("ClassName")=trim(request("ClassName"))
rs("WebName")=trim(request("WebName"))
rs("TrueNameYear")=trim(request("TrueNameYear"))
rs("TrueNameMoon")=trim(request("TrueNameMoon"))
rs("TrueNameDay")=trim(request("TrueNameDay"))
rs("TrueNameTel")=trim(request("TrueNameTel"))
rs("TrueNameFax")=trim(request("TrueNameFax"))
rs("TrueNameMobile")=trim(request("TrueNameMobile"))
rs("TrueNameCountry")=trim(request("TrueNameCountry"))
rs("TrueNameCity")=trim(request("TrueNameCity"))
rs("Address")=trim(request("Address"))
rs("PostCode")=trim(request("PostCode"))
rs("Email")=trim(request("Email"))
rs("HomePage")=trim(request("HomePage"))
rs("bz")=trim(request("bz"))
rs.update
rs.close
set rs=nothing
response.Write "<table width=90% border=0 align=center cellpadding=0 cellspacing=0><tr><td height=80><font color=#cb6f00>  修改成功</font><br>"
response.Write "<a href=index.asp Class='mnu'>返回首页</a></td></tr></table></td></tr></table>"
end sub
%>

关键字段没有赋值。例如ID。关键字是不能为空的。
#4
2010-05-01 14:29
回复 3楼 zzy_420
谢谢~~
1