❶ 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
❷ ASP.NET中,我連接Access資料庫,想給資料庫中的數據進行update,那句代碼要怎麼寫
string strinsert = "UPDATE 新聞 set NewsName ='" + TextBox1.Text + "',[date] =#" + TextBox2.Text + "#,NewsContent='" + EWebEditorExt1.Text + "' where [id]=" + TextBox3.Text;
❸ asp後台更新資料庫信息
把你上面的asp代碼,放在一個asp文件中,比如Update.asp,然後在你的onClick裡面寫一個js函數,比如還叫你目前的updatestr,你上面的html代碼不用改,這個js腳本向後台的Update.asp頁面傳info_id,執行了單擊後,會調用update.asp,你只要在asp文件中,獲取提交的參數,然後再傳給你的函數做參數,執行你上面的代碼即可。下面是js代碼,用ajax調用Update.asp ,調用完成,刷新當前頁面或者直接修改顯示內容區即可。
function updatestr(info_id)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("您的瀏覽器不支持AJAX!");
return;
}
var url="Update.asp";
url=url+"?id="+info_id;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=function(){UpdateOver()};
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function UpdateOver(div_id)
{
if (xmlHttp.readyState==4)
{
//這里重刷頁面即可
location.reload();
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
❹ 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如何批量更新資料庫數據
第一個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更新資料庫的代碼
<%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>
❼ asp中如何實現sql資料庫更新
if session("Username")="" then
Username=trim(request.form("Username"))
Password=trim(request.form("Password"))
sqlstr="select * from 用戶表 where 用戶名='"&Username&"'and 密碼='"&Password&"'"
set rs=Conn.execute(sqlstr)
if rs.eof then
Response.redirect "err.asp"
end if
session("Username")=Username
session("許可權")=rs("許可權")
sqlstr="update 用戶表 set 上線次數=上線次數+1 where 用戶名='"&Username &"'"
set rs=Conn.execute(sqlstr)
rs.close
end if
❽ 用asp.net(C#)給一段完整的資料庫更新代碼.
我來簡單寫幾句,希望對你有用:
string sqlstr="updata 表名稱 set 欄位=值 where 條件";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(local);Initial Catalog=classmate;User Id=sa;Password=sa";
SqlCommand cmd = new SqlCommand(sqlstr,conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.close();
❾ 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網站批量更新access資料庫代碼怎麼寫求簡單明了的代碼
'這個是我寫的一個審核用戶訂單然後給用戶添加相應積分的。
'你可以參考一些,既然是更新數據就一定要知道ID否則沒得改。
<%
check=request.Form("check")'獲取復選框的值(多選值)
ifcheck<>""then
setrs=server.CreateObject("adodb.recordset")
rs.open"select*from[user_dd]whereidin("&check&")",conn,1,3
'查詢該表中與提交上來的數據
'----------------查詢用戶訂單--------------------------------------
'-----------------------提取用戶表記錄---------------------------------
fori=1tors.recordcount'循環更新數據,從第一條循環到最後一條
conn.execute("update[user]setjifen=jifen+"&rs("z_price")*0.1&"whereusername='"&rs("u_name")&"'")
'對用戶積分進行更新
rs("status")="已審核"
rs.movenext'游標指向下一條訂單信息
next
rs.close
Setrs=nothing
response.Redirect("news_list.asp")
endif
%>