當前位置:首頁 » 操作系統 » asp更新資料庫

asp更新資料庫

發布時間: 2023-02-09 19:14:23

『壹』 asp 中用update更新資料庫

name不是關鍵字嗎? 能取得session值嗎?

『貳』 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放到存儲過程中去

『叄』 ASP資料庫 更新 UPDATE操作語法

倒,,,剛仔細一看,也是你的貼。。。

剛回答了一個網友的同樣的關於update的問題,轉過來一下:
asp更新資料庫時,可以用以下方式(我常用的,還有其他的方式):
一、用recordset記錄集的方式。
rs.open "select * from tablename where id="&request("id"),conn,1,3
rs("a")=request("a")
rs("b")=request("b")
rs.update
rs.close
用這種方式進行數據更新,有個好處就是當要更新的數據量非常大時,也可以很順利的更新成功(比如備注型欄位的數據,中間還包含了換行等等的)

二、用sql的update語句:
conn.execute("update tablename set a='"&request("a")&"',b='"&request("b")&"',c="&request("c")&" where id="&request("id"))

用上面的方法更新數據時,如果是SQL資料庫,而你要更新的數據內容里含有比如單引號['],雙橫線[--]之類的特殊字元,就會更新不成功的,因為這時候SQL會認為是非法字元,而把你的單引號給去掉的。而且當如果更新的是備注型欄位,裡麵包含了換行等字元,也會顯得很亂。但用這種方法更新,速度比用recordset的速度要快很多,因為畢竟這是直接更新資料庫,而recordset是對update的封裝形式。

其實更新資料庫,非常簡單,如果你對字元串連接的單引號,雙引號,&號的使用覺得很混亂,那就用recordset的方式進行,這樣會很清晰,一點都不會有混亂的感覺的。而如果你能熟練的使用單引號,雙引號,&號,那麼你用update語句更新資料庫,就大在的提交了速度(當然如果數據量小,我建議用recordset記錄集的方式,因為這種方式一個欄位對應一個值,一行一個,這樣下來,很清晰,還可以對每行做個備注,以後改起來也方便。而用update的方式,所有的值和記錄全部連在一塊,老長的一串,看得人頭都發麻,而且update還不能添加特殊字元,比如上面說的單引號等。。。)

剛回答的這個問題地址:http://..com/question/18663956.html

『肆』 ASP循環問題,並更新數據到資料庫

1。首先在 FOR 前要定義 I 的值,
2。then 中 和 else 中沒有循環得出不同的數據也是不正常
就算循環成功,最後rss("mb_b") rss("mb_bb") rss("mb_a") rss("mb_aa") 這些值都是統一的,沒有意義
3。ASP不能用 + 連接字元串
4。for i=i to 1 i = rss("mb_id") FOR是每循環一次加一,rss("mb_id")資料庫中絕對不會出現ID為0的

for i = 1 to 100 修改資料庫1-100條記錄 循環是不需要重新給 i 賦值
set rss=server.createobject("adodb.recordset")
sql="select * from 數據訓 where mb_id="&i
rss.open sql,conn,1,1
if rss.eof and rss.bof then 判斷有 沒有這個ID
else
if rss("mb_right")= i then 你的條件成立 修改B模板
rss("mb_b")=mbb+dingdan
rss("mb_bb")=mbbb+dingdan
else 其它條件時修改A模板
rss("mb_a")=mba+dingdan
rss("mb_aa")=mbaa+dingdan
end if
next
end if
rss.close

『伍』 關於ASP更新資料庫的問題

從URL參數可以知道yw3up_k2t取得的值是""(字元串)。但是資料庫里的[科2日期]應該是日期型的吧。如果要把空數據寫入資料庫,那麼應該用null而不是"",其他項也類似。
具體代碼,你可以自己想想,不難!~
希望上面的答案能給你幫助,謝謝

『陸』 asp資料庫更新

你是要在對話框里輸出一個初值吧

value=<%=rs("d_class")%>> 改為 value="<%=rs("d_class")%>"

外面差一對雙引號,多了一個>

『柒』 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
%>

『捌』 asp定時更新資料庫

可以嘗試用windows的計劃任務完成

『玖』 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

熱點內容
r解壓文件 發布:2025-07-23 18:01:01 瀏覽:503
安溪哪裡有賣禮金密碼箱 發布:2025-07-23 17:32:36 瀏覽:528
同等配置藍鳥同軒逸哪個好 發布:2025-07-23 17:31:27 瀏覽:545
雲伺服器圖片載入速度慢 發布:2025-07-23 17:08:16 瀏覽:171
網址導航源碼帶後台 發布:2025-07-23 17:01:40 瀏覽:599
石粉過磅演算法 發布:2025-07-23 16:53:05 瀏覽:78
e盤訪問被拒絕 發布:2025-07-23 16:51:49 瀏覽:349
c語言用什麼編譯器 發布:2025-07-23 16:49:26 瀏覽:571
瀏覽器androidflash 發布:2025-07-23 16:36:38 瀏覽:911
為什麼戰網不用輸入密碼 發布:2025-07-23 16:35:47 瀏覽:938