asp数据库更新
1. asp如何批量更新数据库数据
第一个a.asp页面代码:
<script language=javascript>
function unselectall()
{
if(document.th_edit.chkAll.checked){
document.th_edit.chkAll.checked = document.th_edit.chkAll.checked&0;
}
}
function CheckAll(form)
{
for (var i=0;i<form.elements.length;i++)
{
var e = form.elements[i];
if (e.Name != "chkAll")
e.checked = form.chkAll.checked;
}
}
function ConfirmDel()
{
if(confirm("确定要修改吗?"))
return true;
else
return false;
}
</script>
</head>
<body>
<%
sub_number=request("sub_number")
sub_stores=request("sub_stores")
set rs=server.CreateObject("ADODB.Recordset")
sql="select * from venshop_basket where sub_number='"+sub_number+"'"
rs.open sql,conn,1,3
%>
<table>
<tr>
<td>商品名称</td>
<td>订购数量</td>
<td>退货数量</td>
<td>配送门店</td>
<td>下单时间</td>
<td>退货原因</td>
</tr>
<form action="th_update.asp" name="th_edit" method="post" onSubmit="return ConfirmDel();"><%
do while not rs.eof
%>
<tr>
<td><input name="delid" type="checkbox" onClick="unselectall()" id="delid" value='<%=cstr(rs("basket_id"))%>'><%=rs("hw_name")%>
</td>
<td><%=rs("basket_count")%></td>
<td><input type="text" name="thcount" value='<%=rs("basket_count")%>'></td>
<td><%=sub_stores%></td>
<td><%=rs("basket_date")%></td>
<td><input type="text" name="yuanyin"></td>
</tr>
<%
rs.movenext
loop
%>
<tr>
<td><input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this.form)" value="checkbox" />全选</td>
<td><input type="submit" name="tuihuo" value="退货"></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</form>
</table>
<%
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
</body>
</html>
th_update.asp页面代码:
<!--#include file="conn.asp"-->
<!--#include file="ad_chk.asp"-->
<%
If Request("delid") & ""="" then
response.write "<script>alert('请选择要修改的信息!');history.go(-1);</script>"
else
arrdel=Request("delid")
basket_count=Request("basket_count")
thcount=Request("thcount")
for i=1 to arrdel.count
sql="update venshop_basket set basket_count='" & thcount(i) & "' where basket_id='" & arrdel(i) & "'"
conn.Execute sql
next
set conn=nothing
response.write "<script language=JavaScript>alert('修改成功!');location.href=ad_sub.asp;<script>"
response.Redirect("ad_sub.asp")
end if
%>
2. asp定时更新数据库
可以尝试用windows的计划任务完成
3. asp如何更新一条数据库记录使用update
<%
'连接数据库 db.mdb是您的数据库文件
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db.mdb")
conn.open connstr
'执行语句
conn.execute "update [表名] set [列名]=值 where [id]=编号"
%>
如下面一个数据库
数据库文件名 123.mdb
表名 userinfo
数据/列名 id username password
0 lorabit PiG!!!
1 paint DoG!!!
当paint用户需要更新其密码为PiG!!!时,我们就需要这样一段ASP
<%
'连接数据库 db.mdb是您的数据库文件
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("123.mdb")
conn.open connstr
'执行语句
conn.execute "update [userinfo] set [password]='PiG!!!' where [id]=1"
%>
你也可以使用下面这一段,两段的差别在于第一段是靠用户ID来确定行,而第二段是搜索用户名。
<%
'连接数据库 db.mdb是您的数据库文件
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("123.mdb")
conn.open connstr
'执行语句
conn.execute "update [userinfo] set [password]='PiG!!!' where [username]='paint'"
%>
如果还有不懂 QQ233349789
4. ASP 更新数据库 数据 问题
首先得弄清楚数据表中的DDid和ReferferID这两个字段的数据类型,如果是ddid和ReferferID都是数字类型的话,那就应该改为:sql="update dingdan set refererID="&refererID&" where DDid="&DDid,否则就要先知道数据类型才方便写出程序了。如果还不行的话,你就把两个字段的数据类型写出来,我再帮你解决!
5. asp 中用update更新数据库
name不是关键字吗? 能取得session值吗?
6. ASP 更新数据库字段内容
插入到你现有的ASP程序中
如何保存更新内容呢?
数据库结构:(一共三个字段)QuoteID(Long ),Quote(String ),Author(String)
下面一个技巧是如何让更新显示在任意一个页面上呢?
我们只要把更新内容和作者当返回值送给调用的页面即可。代码如下,其中logic是一个随机数,表示随机从数据库中显示哪个记录:
<%
Sub GetQuote(byVal strQuote, byval strAuthor)
Dim intMaxID&
Dim intRecordID
dim strSQL&
Dim oConn&
Dim oRS
set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Database=mydb;DSN=Quotes;UID=sa;Password=;"
strSQL = "SELECT MaxID=max(QuoteId) from Quotes"
Set oRS = oConn.Execute(strSQL)
If oRS.EOF Then
strQuote = "站长太懒了,今天没有更新内容."
strAuthor = "呵呵"
Exit Sub
Else
intMaxID = oRS("MaxID")
End If
Randomize
intRecordID= Int(Rnd * intMaxID) + 1
strSQL = "Select * from quotes where QuoteID=" & intRecordID & ";"
Set oRS = oConn.Execute(strSQL)
If oRS.EOF Then
strQuote = "站长太懒了,今天没有更新内容."
strAuthor = "呵呵"
Exit Sub
Else
oRS.MoveFirst
strQuote = oRS("Quote")
strAuthor = oRS("Author")
End If
oRS.Close
oConn.Close
Set oRS = Nothing
set oConn = Nothing
End Sub
%>
其实在程序中如果使用一个嵌套的SQL能够提高性能,例如这样
Select * from Quotes where QuoteID = (Select int ( RND * Max(QuoteID) ) from Quotes );
可是问题是有些数据库的随机数函数是RAND而不是RND,如果要是你自己用的话,那当然可以使用这句话代替我上面介绍的方法,可别忘了,要是别人的数据库不支持RAND怎么办,呵呵。
现在我们将上面的代码保存到一个名叫quotes.inc的文件中来,下面就举一个如何调用它的例子把:
<HTML>
<HEAD>
<TITLE>例子</TITLE>
<!--#include virtual = "quotes.inc" -->
</HEAD>
<BODY>
<BR><BR>
<%
Dim strQuote
Dim strAuthor
GetQuote(strQuote, strAuthor)
%>
<TABLE BORDER=0 CELLPADDING=6 CELLSPACING=5 BGCOLOR="#000000" WIDTH=500>
<TR BGCOLOR="#CCCCCC">
<TD ALIGN=CENTER>
<B>"<% =strQuote %>" <BR>--<I><% =strAuthor %></I></B>
</TD>
</TR>
</TABLE>
<BR><BR>
</BODY>
</HTML>
其实你可以再加强点它的功能:
1.可以在子过程中给返回的字符串带上格式,这样显示会更加漂亮
2。将这个代码做成一个组件来调用
3。使用一个文本文件来代替数据库
4。将SQL放到存储过程中去
7. ASP更新数据库的代码
<%set rst=server.createobject("adodb.recordset")sql="select top 1 * from wpjy where wpjy_id like '%" & id & "%' order by wpjy_id desc "rst.open sql,conn,1,3 if rst.eof thenrst.addnewrst("wpjy_rq")=rst("wpjy_rq")+1rst.update
end ifrst.closeset rst=nothing%></p>
8. ASP中如何即时的显示数据库中的更新数据
ASP比较麻烦,或者说不能完全做到,你想把ASP页面做成QQ那样及时通信功能。肯定不行。(例如,你发条信息给你的好友,你的好友会立即收到此信息。)但是可以做成相似的东西出来。
你可以这样想。页面怎样及时显示数据库里跟新的数据。你肯定需要刷新页面才能看到。是不是?
换句话说:我要是能实现,页面能够自动刷新。当然是这样的思路。但是还是有个问题。ASP怎么能及时刷新呢?当有新数据添加时就自动刷新页面呢?这个ASP是办不到的。那我们怎么解决这个问题呢?我们可以试试下面的方法:
折中的办法:这个要用到javascript。比如,定时为1秒中自动刷新页面。这里你要注意,你设置刷新的时间越小也就是说,你网页刷新的越频繁,对你服务器的负载是最大的。你本地测试到时可以试试。真正用到web引用上,是不建议的。所以说:ASP不能完全做成及时显示的工能。如果真想做,只能换其他语言了。例如C,C++。然后再配合web语言。以达到效果。
例如,现在某些产品已经做得很好了。53kf。就是你说的那种功能。不知道他们提不提供源码。你可以去研究研究。
9. ASP问题:利用ASP对数据库进行更新操作
也可以试试我的:
sqlstr="update student set 成绩="&score
sqlstr=sqlstr&" where 学号="&no
或
sqlstr="update student set 成绩="&score&" where 学号="&no