sos!!sos!!初学者的asp小问题。(请高手们帮忙!!高分)

fangfang_2005 2005-09-06 08:51:01
我在Dreamweaver下建立了一个asp连接数据库的学生查分系统。(用odbc).但是我的更新程序和删除程序只能对第一条记录进行操作!!哪位高手能帮帮小女子呢?小女子将不胜感激。
http://163.mopbus.com/aspxt.rar
这个连接能下载到我做的源程序。
再有我的这个asp程序能变成ado连接的吗?(因为配置odbc太麻烦了。)
...全文
129 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
muziruyue 2005-09-07
  • 打赏
  • 举报
回复
很简单
漫漫来
帮你顶
fangfang_2005 2005-09-07
  • 打赏
  • 举报
回复
谢谢楼上的朋友。:)我不急。只要能改过来,一个世纪都成。嘻嘻。:)
jingxiaoping 2005-09-07
  • 打赏
  • 举报
回复
你如果不着急要的话,我今天下午下班后替你改一下。
fangfang_2005 2005-09-06
  • 打赏
  • 举报
回复
updatestu.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/wxy.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Update Record: set variables

If (CStr(Request("MM_update")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

MM_editConnection = MM_wxy_STRING
MM_editTable = "simplestudent"
MM_editColumn = "id"
MM_recordId = "'" + Request.Form("MM_recordId") + "'"
MM_editRedirectUrl = "browsestu.asp"
MM_fieldsStr = "id|value|name|value|sex|value|age|value|dorm|value|phone|value"
MM_columnsStr = "id|',none,''|name|',none,''|sex|',none,''|age|none,none,NULL|dorm|',none,''|phone|none,none,NULL"

' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")

' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Update Record: construct a sql update statement and execute it

If (CStr(Request("MM_update")) <> "" And CStr(Request("MM_recordId")) <> "") Then

' create the sql update statement
MM_editQuery = "update " & MM_editTable & " set "
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_editQuery = MM_editQuery & ","
End If
MM_editQuery = MM_editQuery & MM_columns(MM_i) & " = " & MM_formVal
Next
MM_editQuery = MM_editQuery & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the update
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim update
Dim update_numRows

Set update = Server.CreateObject("ADODB.Recordset")
update.ActiveConnection = MM_wxy_STRING
update.Source = "SELECT * FROM simplestudent"
update.CursorType = 0
update.CursorLocation = 2
update.LockType = 1
update.Open()

update_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<p> </p>

<p> </p>

<p> </p>

<form method="post" action="<%=MM_editAction%>" name="form1">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Id:</td>
<td><input type="text" name="id" value="<%=(update.Fields.Item("id").Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Name:</td>
<td><input type="text" name="name" value="<%=(update.Fields.Item("name").Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Sex:</td>
<td><input type="text" name="sex" value="<%=(update.Fields.Item("sex").Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Age:</td>
<td><input type="text" name="age" value="<%=(update.Fields.Item("age").Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Dorm:</td>
<td><input type="text" name="dorm" value="<%=(update.Fields.Item("dorm").Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Phone:</td>
<td><input type="text" name="phone" value="<%=(update.Fields.Item("phone").Value)%>" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="更新记录">
</td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%= update.Fields.Item("id").Value %>">
</form>
<p> </p>
</body>
</html>
<%
update.Close()
Set update = Nothing
%>
fangfang_2005 2005-09-06
  • 打赏
  • 举报
回复
deletestu.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/wxy.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Delete Record: declare variables

if (CStr(Request("MM_delete")) = "form1" And CStr(Request("MM_recordId")) <> "") Then

MM_editConnection = MM_wxy_STRING
MM_editTable = "simplestudent"
MM_editColumn = "id"
MM_recordId = "'" + Request.Form("MM_recordId") + "'"
MM_editRedirectUrl = "ok.asp"

' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%>
<%
' *** Delete Record: construct a sql delete statement and execute it

If (CStr(Request("MM_delete")) <> "" And CStr(Request("MM_recordId")) <> "") Then

' create the sql delete statement
MM_editQuery = "delete from " & MM_editTable & " where " & MM_editColumn & " = " & MM_recordId

If (Not MM_abortEdit) Then
' execute the delete
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close

If (MM_editRedirectUrl <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%>
<%
Dim deletestu
Dim deletestu_numRows

Set deletestu = Server.CreateObject("ADODB.Recordset")
deletestu.ActiveConnection = MM_wxy_STRING
deletestu.Source = "SELECT * FROM simplestudent"
deletestu.CursorType = 0
deletestu.CursorLocation = 2
deletestu.LockType = 1
deletestu.Open()

deletestu_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<form ACTION="<%=MM_editAction%>" METHOD="POST" name="form1">
<table width="436" border="1" align="center">
<tr>
<td colspan="2">真的删除吗?</td>
</tr>
<tr>
<td width="99">姓名</td>
<td width="321"><input name="textfield" type="text" value="<%=(deletestu.Fields.Item("name").Value)%>"></td>
</tr>
<tr>
<td>学号</td>
<td><input name="textfield" type="text" value="<%=(deletestu.Fields.Item("id").Value)%>"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="Submit" value="提交"></td>
</tr>
</table>






<input type="hidden" name="MM_delete" value="form1">
<input type="hidden" name="MM_recordId" value="<%= deletestu.Fields.Item("id").Value %>">
</form>

</body>
</html>
<%
deletestu.Close()
Set deletestu = Nothing
%>
fangfang_2005 2005-09-06
  • 打赏
  • 举报
回复
detailstu.asp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<table width="397" height="161" border="1" align="center">
<tr>
<td width="109"><div align="right">学号</div></td>
<td width="416"><%=(detail.Fields.Item("id").Value)%></td>
</tr>
<tr>
<td><div align="right">姓名</div></td>
<td><%=(detail.Fields.Item("name").Value)%></td>
</tr>
<tr>
<td><div align="right">性别</div></td>
<td><%=(detail.Fields.Item("sex").Value)%></td>
</tr>
<tr>
<td><div align="right">年龄</div></td>
<td><%=(detail.Fields.Item("age").Value)%></td>
</tr>
<tr>
<td><div align="right">宿舍号</div></td>
<td><%=(detail.Fields.Item("dorm").Value)%></td>
</tr>
<tr>
<td><div align="right">电话</div></td>
<td><%=(detail.Fields.Item("phone").Value)%></td>
</tr>
</table>
<p align="center"><A HREF="updatestu.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "id=" & detail.Fields.Item("id").Value %>">更新</A>  <A HREF="deletestu.asp?<%= Server.HTMLEncode(MM_keepNone) & MM_joinChar(MM_keepNone) & "id=" & detail.Fields.Item("id").Value %>">删除</A></p>
</body>
</html>
<%
detail.Close()
Set detail = Nothing
%>
FlashK 2005-09-06
  • 打赏
  • 举报
回复
ADO:
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionString = "driver={SQL Server};server=127.0.0.1;uid=sa;pwd=as;database=web_db"
conn.Open

删除不了,你把SQL语句打印出来,有可能是你没有进行循环。

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧