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