mysql autoenlist默认_javascript code all (2) (转转)
1. οncοntextmenu="window.event.returnvalue=false" 將徹底屏蔽鼠標(biāo)右鍵
可用于Table2.
取消選取、防止復(fù)制3. οnpaste="return false" 不準(zhǔn)粘貼
4. οncοpy="return false;" oncut="return false;" 防止復(fù)制
5. IE地址欄前換成自己的圖標(biāo)
6. 可以在收藏夾中顯示出你的圖標(biāo)
7. 關(guān)閉輸入法
8. 永遠(yuǎn)都會帶著框架
if (window == top)top.location.href = "frames.htm"; //frames.htm為框架網(wǎng)頁
// -->
9. 防止被人frame
if (top.location != self.location)top.location=self.location;
// -->
10.
html> 網(wǎng)頁將不能被另存為11.
οnclick="window.location = 'view-source:'+ 'http://www.csdn.net/'">
12. 怎樣通過asp的手段來檢查來訪者是否用了代理
"" then
response.write "您通過了代理服務(wù)器,"& _
"真實(shí)的IP為"&Request.ServerVariables("HTTP_X_FORWARDED_FOR")
end if
%>
13. 取得控件的絕對位置
//javascript
function getIE(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
alert("top="+t+"/nleft="+l);
}
//VBScript
function getIE()
dim t,l,a,b
set a=document.all.img1
t=document.all.img1.offsetTop
l=document.all.img1.offsetLeft
while a.tagName"BODY"
set a = a.offsetParent
t=t+a.offsetTop
l=l+a.offsetLeft
wend
msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
end function
-->
14. 光標(biāo)是停在文本框文字的最后
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart('character',e.value.length);
r.collapse(true);
r.select();
}
15. 判斷上一頁的來源
asp:
request.servervariables("HTTP_REFERER")
javascript:
document.referrer
16. 最小化、最大化、關(guān)閉窗口
本例適用于IE
17.
'定義數(shù)據(jù)庫連接的一些常量
Const adOpenForwardOnly = 0 '游標(biāo)只向前瀏覽記錄,不支持分頁、Recordset、BookMark
Const adOpenKeyset = 1 '鍵集游標(biāo),其他用戶對記錄說做的修改將反映到記錄集中,但其他用戶增加或刪除記錄不會反映到記錄集中。支持分頁、Recordset、BookMark
Const adOpenDynamic = 2 '動態(tài)游標(biāo)功能最強(qiáng),但耗資源也最多。用戶對記錄說做的修改,增加或刪除記錄都將反映到記錄集中。支持全功能瀏覽(ACCESS不支持)。
Const adOpenStatic = 3 '靜態(tài)游標(biāo),只是數(shù)據(jù)的一個快照,用戶對記錄說做的修改,增加或刪除記錄都不會反映到記錄集中。支持向前或向后移動
Const adLockReadOnly = 1 '鎖定類型,默認(rèn)的,只讀,不能作任何修改
Const adLockPessimistic = 2 '當(dāng)編輯時立即鎖定記錄,最安全的方式
Const adLockOptimistic = 3 '只有在調(diào)用Update方法時才鎖定記錄集,而在此前的其他操作仍可對當(dāng)前記錄進(jìn)行更改、插入和刪除等
Const adLockBatchOptimistic = 4 '當(dāng)編輯時記錄不會被鎖定,而更改、插入和刪除是在批處理方式下完成的
Const adCmdText = &H0001
Const adCmdTable = &H0002
%>
18. 網(wǎng)頁不會被緩存
HTM網(wǎng)頁
或者
ASP網(wǎng)頁
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.cachecontrol = "no-cache"
PHP網(wǎng)頁
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
19. 檢查一段字符串是否全由數(shù)字組成
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// -->
20. 獲得一個窗口的大小
document.body.clientWidth,document.body.clientHeight
21. 怎么判斷是否是字符
if (/[^/x00-/xff]/g.test(s)) alert("含有漢字");
else alert("全是字符");
22.TEXTAREA自適應(yīng)文字行數(shù)的多少
23. 日期減去天數(shù)等于第二個日期
function cc(dd,dadd)
{
//可以加上錯誤處理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
}
cc("12/23/2002",2)
24. 選擇了哪一個Radio
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
next
end function
Style
Barcode
25.獲得本頁url的request.servervariables("")集合
Response.Write "
| Variables | value |
for each ob in Request.ServerVariables
Response.Write "
"&ob&""&Request.ServerVariables(ob)&""next
Response.Write "
"26.
本機(jī)ip
服務(wù)器名
服務(wù)器IP
服務(wù)器端口
服務(wù)器時間
IIS版本
腳本超時時間
本文件路徑
服務(wù)器CPU數(shù)量
服務(wù)器解譯引擎
服務(wù)器操作系統(tǒng)
27.ENTER鍵可以讓光標(biāo)移到下一個輸入框
28. 檢測某個網(wǎng)站的鏈接速度:
把如下代碼加入
區(qū)域中:tim=1
setInterval("tim++",100)
b=1
var autourl=new Array()
autourl[1]="www.njcatv.net"
autourl[2]="javacool.3322.net"
autourl[3]="www.sina.com.cn"
autourl[4]="www.nuaa.edu.cn"
autourl[5]="www.cctv.com"
function butt(){
document.write("
")for(var i=1;i
document.write(" =》 =》
")
document.write("
")}
butt()
function auto(url){
document.forms[0]["url"+b].value=url
if(tim>200)
{document.forms[0]["txt"+b].value="鏈接超時"}
else
{document.forms[0]["txt"+b].value="時間"+tim/10+"秒"}
b++
}
function run(){for(var i=1;i")}
run()
29. 各種樣式的光標(biāo)
auto :標(biāo)準(zhǔn)光標(biāo)
default :標(biāo)準(zhǔn)箭頭
hand :手形光標(biāo)
wait :等待光標(biāo)
text :I形光標(biāo)
vertical-text :水平I形光標(biāo)
no-drop :不可拖動光標(biāo)
not-allowed :無效光標(biāo)
help :?幫助光標(biāo)
all-scroll :三角方向標(biāo)
move :移動標(biāo)
crosshair :十字標(biāo)
e-resize
n-resize
nw-resize
w-resize
s-resize
se-resize
sw-resize
Top
7 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 07:40:39 得分 0
1.本地?zé)o緩存,每次自動刷新
response.expires=0
response.addHeader pragma , no-cache
response.addHeader cache-control , private
2.修改contentType并下載gif等格式
function dl(f,n)
on error resume next
set s=CreateObject(Adodb.Stream)
S.Mode=3
S.Type=1
S.Open
s.LoadFromFile(server.mappath(f))
if err.number>0 then
response.write err.number & : & err.description
else
response.contentType=application/x-gzip
response.addheader Content-Disposition:,attachment; filename= & n
response.binarywrite(s.Read(s.size))
end if
end function
call dl(012922501.gif,t1.gif)
%>
Top
8 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 07:43:11 得分 0
1。忽視右鍵
或
2。加入背景音樂
IE:
NS:
*.mid你的背景音樂的midi格式文件
3。簡單的window.open方法
οnclick="javascript:window.open(文件路徑/文件名,newwindow,
toolbar=no,scrollbars=yes,resizable=no,top=0,left=0,
width=400,height=300);">文字或圖片
參數(shù)解釋:
window.open 彈出新窗口的命令;
文件路徑/文件名 彈出窗口的文件名;
newwindow 彈出窗口的名字(不是文件名),非必須,可用空代替;
width=400 窗口寬度;
height=300 窗口高度;
top=0 窗口距離屏幕上方的象素值;
left=0 窗口距離屏幕左側(cè)的象素值;
toolbar=no 是否顯示工具欄,yes為顯示;
menubar,scrollbars 表示菜單欄和滾動欄。
resizable=no 是否允許改變窗口大小,yes為允許;
location=no 是否顯示地址欄,yes為允許;
status=no 是否顯示狀態(tài)欄內(nèi)的信息(通常是文件已經(jīng)打開),yes為允許;
js腳本結(jié)束
4。簡單的頁面加密
5。拉動頁面時背景圖不動
body{background-image:url(logo.gif);
background-repeat:no-repeat;background-position:center}
7。隨機(jī)替換圖片
document.write()
圖片文件名為0.gif 1.gif 2.gif 3.gif 4.gif
8。窗口定時關(guān)閉
先將如下代碼網(wǎng)頁文件的區(qū):
function closeit() { setTimeout("self.close()",10000) //毫秒 }
然后再在
標(biāo)內(nèi)加入如:9。網(wǎng)頁自動關(guān)閉
classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
這個窗口會在10秒過后自動關(guān)閉,而且不會出現(xiàn)提示.
10。網(wǎng)頁自動刷新
在head部記入
其中20為20秒后自動刷新,你可以更改為任意值。
11。網(wǎng)頁自動轉(zhuǎn)頁
12。保持layer在最前面,而不被Iframe、Object所覆蓋
在Layer中再插Iframe 或 Object 設(shè)z-Index值
# 前面# 后面height=100% width=100%>13。返回上一頁
『返回上一頁』
14。關(guān)閉窗口
『關(guān)閉窗口』
15。關(guān)于iframe的透明背景
allowTransparency="true"
style="background-color: green">
Top9 樓net_lover(【孟子E章】)回復(fù)于 2005-12-23 08:13:18 得分 2
支持!Top
10 樓ybfqlyq(Rossy|http://blog.ybfq.com)回復(fù)于 2005-12-23 08:13:51 得分 2
捧場!支持JSPADMIN!
貼個分頁代碼
sql="select id,name,count from [table] "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
RS.pagesize=15 '每頁記錄數(shù)
page=cint(request("page"))
if page="" or page=0 then
page=1
else
page=page
end if
rs.absolutepage=page '取得當(dāng)前頁
for i=1 to rs.pagesize
if rs.bof or rs.eof then
exit for
end if
%>
rs.movenext
next%>
每頁15條記錄??總共有
條記錄?
If Page <= 1 Then
Response.Write "首頁? "
Response.Write "上一頁? "
End If
If Page > 1 Then
Response.Write "首頁 "
Response.Write "上一頁 "
End If
If Page < RS.PageCount Then
Response.Write "下一頁 "
Response.Write "末頁 "
End If
If Page >= RS.PageCount Then
Response.Write "下一頁? "
Response.Write "末頁? "
End If
response.write ""
%>
selected>
第頁/共頁
Top11 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 08:20:18 得分 0
1.如何用Asp判斷你的網(wǎng)站的虛擬物理路徑
答:使用Mappath方法
< p align="center" >< font size="4" face="Arial" >< b >
The Physical path to this virtual website is:
< /b >< /font >
< font color="#FF0000" size="6" face="Arial" >
< %= Server.MapPath("/")% >
< /font >< /p >
2.我如何知道使用者所用的瀏覽器?
答:使用the Request object方法
strBrowser=Request.ServerVariables("HTTP_USER_AGENT")
If Instr(strBrowser,"MSIE") < > 0 Then
Response.redirect("ForMSIEOnly.htm")
Else
Response.redirect("ForAll.htm")
End If
3.如何計(jì)算每天的平均反復(fù)訪問人數(shù)
答:解決方法
< % startdate=DateDiff("d",Now,"01/01/1990")
if strdate< 0 then startdate=startdate*-1
avgvpd=Int((usercnt)/startdate) % >
顯示結(jié)果
< % response.write(avgvpd) % >
that is it.this page have been viewed since November 10,1998
4.如何顯示隨機(jī)圖象
< % dim p,ppic,dpic
ppic=12
randomize
p=Int((ppic*rnd)+1)
dpic="graphix/randompics/"&p&".gif"
% >
顯示
< img src="< %=dpic% >" >
5.如何回到先前的頁面
答:< a href="< %=request.serverVariables("Http_REFERER")% >" >preivous page< /a >
或用圖片如:< img src="arrowback.gif" alt="< %=request.serverVariables("HTTP_REFERER")% >" >
6.如何確定對方的IP地址
答:< %=Request.serverVariables("REMOTE_ADDR)% >
7.如何鏈結(jié)到一副圖片上
答:< % @Languages=vb-script % >
< % response.expires=0
strimagename="graphix/errors/erroriamge.gif"
response.redirect(strimagename)
% >
8.強(qiáng)迫輸入密碼對話框
答:把這句話放載頁面的開頭
< % response.status="401 not Authorized"
response.end
% >
9.如何傳遞變量從一頁到另一頁
答:用 HIDDEN 類型來傳遞變量
< % form method="post" action="mynextpage.asp" >
< % for each item in request.form % >
< input namee="< %=item% >" type="HIDDEN"
value="< %=server.HTMLEncode(Request.form(item)) % >" >
< % next % >
< /form >
10.為何我在 asp 程序內(nèi)使用 msgbox,程序出錯說沒有權(quán)限
答:由于 asp 是服務(wù)器運(yùn)行的,如果可以在服務(wù)器顯示一個對話框,那么你只好等有人按了確定之后,你的程序才能繼續(xù)執(zhí)行,而一般服務(wù)器不會有人守著,所以微軟不得不禁止這個函數(shù),并胡亂告訴你 (:) 呵呵) 沒有權(quán)限。但是ASP和客戶端腳本結(jié)合倒可以顯示一個對話框,as follows:
< % yourVar="測試對話框"% >
< % script language='java-script' >
alert("< %=yourvar% >")
< /script >
11.有沒有辦法保護(hù)自己的源代碼,不給人看到
答:可以去下載一個微軟的Windows Script Encoder,它可以對asp的腳本和客戶端java-script/vb-script腳本進(jìn)行加密。。。不過客戶端加密后,只有ie5才能執(zhí)行,服務(wù)器端腳本加密后,只有服務(wù)器上安裝有script engine 5(裝一個ie5就有了)才能執(zhí)行。
12.怎樣才能將 query string 從一個 asp 文件傳送到另一個?
答:前者文件加入下句: Response.Redirect("second.asp?" & Request.ServerVariables("QUERY_STRING"))
13.global.asa文件總是不起作用?
答:只有web目錄設(shè)置為web application, global.asa才有效,并且一個web application的根目錄下 global.asa才有效。IIS4可以使用Internet Service Manager設(shè)置application setting 怎樣才能使得htm文件如同asp文件一樣可以執(zhí)行腳本代碼?
14.怎樣才能使得htm文件如同asp文件一樣可以執(zhí)行腳本代碼?
答:Internet Sevices Manager - > 選擇default web site - >右鼠鍵- >菜單屬性-〉主目錄- > 應(yīng)用程序設(shè)置(Application Setting)- > 點(diǎn)擊按鈕 "配置"- > app mapping - >點(diǎn)擊按鈕"Add" - > executable browse選擇 /WINNT/SYSTEM32/INETSRV/ASP.DLL EXTENSION 輸入 htm method exclusions 輸入PUT.DELETE 全部確定即可。但是值得注意的是這樣對htm也要由asp.dll處理,效率將降低。
15.如何注冊組件
答:有兩種方法。
第一種方法:手工注冊 DLL 這種方法從IIs 3.0一直使用到IIs 4.0和其它的Web Server。它需要你在命令行方式下來執(zhí)行,進(jìn)入到包含有DLL的目錄,并輸入:regsvr32 component_name.dll 例如 c:/temp/regsvr32 AspEmail.dll 它會把dll的特定信息注冊入服務(wù)器中的注冊表中。然后這個組件就可以在服務(wù)器上使用了,但是這個方法有一個缺陷。當(dāng)使用這種方法注冊完畢組件后,該組件必須要相應(yīng)的設(shè)置NT的匿名帳號有權(quán)限執(zhí)行這個dll。特別是一些組件需要讀取注冊表,所以,這個注冊組件的方法僅僅是使用在服務(wù)器上沒有MTS的情況下,要取消注冊這個dll,使用:regsvr32 /u aspobject.dll example c:/temp/regsvr32 /u aneiodbc.dll
第二種方法:使用MTS(Microsoft Transaction Server) MTS是IIS 4新增特色,但是它提供了巨大的改進(jìn)。MTS允許你指定只有有特權(quán)的用戶才能夠訪問組件,大大提高了網(wǎng)站服務(wù)器上的安全性設(shè)置。在MTS上注冊組件的步驟如下:
1) 打開IIS管理控制臺。
2) 展開transaction server,右鍵單擊"pkgs installed"然后選擇"new package"。
3) 單擊"create an empty package"。
4) 給該包命名。
5) 指定administrator帳號或則使用"interactive"(如果服務(wù)器經(jīng)常是使用administrator 登陸的話)。
6) 現(xiàn)在使用右鍵單擊你剛建立的那個包下面展開后的"components"。選擇 "new then component"。
7) 選擇 "install new component" [b]。
8) 找到你的.dll文件然后選擇next到完成。
要刪除這個對象,只要選擇它的圖標(biāo),然后選擇delete。
附注:特別要注意第二種方法,它是用來調(diào)試自己編寫組件的最好方法,而不必每次都需要重新啟動機(jī)器了。
16. ASP與Access數(shù)據(jù)庫連接:
dim conn,mdbfile
mdbfile=server.mappath("數(shù)據(jù)庫名稱.mdb")
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};uid=admin;pwd=數(shù)據(jù)庫密碼;dbq="&mdbfile
%>
17. ASP與SQL數(shù)據(jù)庫連接:
dim conn
set conn=server.createobject("ADODB.connection")
con.open "PROVIDER=SQLOLEDB;DATA SOURCE=SQL服務(wù)器名稱或IP地址;UID=sa;PWD=數(shù)據(jù)庫密碼;DATABASE=數(shù)據(jù)庫名稱
%>
建立記錄集對象:
set rs=server.createobject("adodb.recordset")
rs.open SQL語句,conn,3,2Top
12 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 08:21:01 得分 0
18. SQL常用命令使用方法:
(1) 數(shù)據(jù)記錄篩選:
sql="select * from 數(shù)據(jù)表 where 字段名=字段值 order by 字段名 [desc]"
sql="select * from 數(shù)據(jù)表 where 字段名 like '%字段值%' order by 字段名 [desc]"
sql="select top 10 * from 數(shù)據(jù)表 where 字段名 order by 字段名 [desc]"
sql="select * from 數(shù)據(jù)表 where 字段名 in ('值1','值2','值3')"
sql="select * from 數(shù)據(jù)表 where 字段名 between 值1 and 值2"
(2) 更新數(shù)據(jù)記錄:
sql="update 數(shù)據(jù)表 set 字段名=字段值 where 條件表達(dá)式"
sql="update 數(shù)據(jù)表 set 字段1=值1,字段2=值2 …… 字段n=值n where 條件表達(dá)式"
(3) 刪除數(shù)據(jù)記錄:
sql="delete from 數(shù)據(jù)表 where 條件表達(dá)式"
sql="delete from 數(shù)據(jù)表" (將數(shù)據(jù)表所有記錄刪除)
(4) 添加數(shù)據(jù)記錄:
sql="insert into 數(shù)據(jù)表 (字段1,字段2,字段3 …) valuess (值1,值2,值3 …)"
sql="insert into 目標(biāo)數(shù)據(jù)表 select * from 源數(shù)據(jù)表" (把源數(shù)據(jù)表的記錄添加到目標(biāo)數(shù)據(jù)表)
(5) 數(shù)據(jù)記錄統(tǒng)計(jì)函數(shù):
AVG(字段名) 得出一個表格欄平均值
COUNT(*|字段名) 對數(shù)據(jù)行數(shù)的統(tǒng)計(jì)或?qū)δ骋粰谟兄档臄?shù)據(jù)行數(shù)統(tǒng)計(jì)
MAX(字段名) 取得一個表格欄最大的值
MIN(字段名) 取得一個表格欄最小的值
SUM(字段名) 把數(shù)據(jù)欄的值相加
引用以上函數(shù)的方法:
sql="select sum(字段名) as 別名 from 數(shù)據(jù)表 where 條件表達(dá)式"
set rs=conn.excute(sql)
用 rs("別名") 獲取統(tǒng)的計(jì)值,其它函數(shù)運(yùn)用同上。
(5) 數(shù)據(jù)表的建立和刪除:
CREATE TABLE 數(shù)據(jù)表名稱(字段1 類型1(長度),字段2 類型2(長度) …… )
例:CREATE TABLE tab01(name varchar(50),datetime default now())
DROP TABLE 數(shù)據(jù)表名稱 (永久性刪除一個數(shù)據(jù)表)
19. 記錄集對象的方法:
rs.movenext 將記錄指針從當(dāng)前的位置向下移一行
rs.moveprevious 將記錄指針從當(dāng)前的位置向上移一行
rs.movefirst 將記錄指針移到數(shù)據(jù)表第一行
rs.movelast 將記錄指針移到數(shù)據(jù)表最后一行
rs.absoluteposition=N 將記錄指針移到數(shù)據(jù)表第N行
rs.absolutepage=N 將記錄指針移到第N頁的第一行
rs.pagesize=N 設(shè)置每頁為N條記錄
rs.pagecount 根據(jù) pagesize 的設(shè)置返回總頁數(shù)
rs.recordcount 返回記錄總數(shù)
rs.bof 返回記錄指針是否超出數(shù)據(jù)表首端,true表示是,false為否
rs.eof 返回記錄指針是否超出數(shù)據(jù)表末端,true表示是,false為否
rs.delete 刪除當(dāng)前記錄,但記錄指針不會向下移動
rs.addnew 添加記錄到數(shù)據(jù)表末端
rs.update 更新數(shù)據(jù)表記錄
---------------------------------------
20 Recordset對象方法
Open方法
recordset.Open Source,ActiveConnection,CursorType,LockType,Options
Source
Recordset對象可以通過Source屬性來連接Command對象。Source參數(shù)可以是一個Command對象名稱、一段SQL命令、一個指定的數(shù)據(jù)表名稱或是一個Stored Procedure。假如省略這個參數(shù),系統(tǒng)則采用Recordset對象的Source屬性。
ActiveConnection
Recordset對象可以通過ActiveConnection屬性來連接Connection對象。這里的ActiveConnection可以是一個Connection對象或是一串包含數(shù)據(jù)庫連接信息(ConnectionString)的字符串參數(shù)。
CursorType
Recordset對象Open方法的CursorType參數(shù)表示將以什么樣的游標(biāo)類型啟動數(shù)據(jù),包括adOpenForwardOnly、adOpenKeyset、adOpenDynamic及adOpenStatic,分述如下:
--------------------------------------------------------------
常數(shù) 常數(shù)值 說明
-------------------------------------------------------------
adOpenForwardOnly 0 缺省值,啟動一個只能向前移動的游標(biāo)(Forward Only)。
adOpenKeyset 1 啟動一個Keyset類型的游標(biāo)。
adOpenDynamic 2 啟動一個Dynamic類型的游標(biāo)。
adOpenStatic 3 啟動一個Static類型的游標(biāo)。
-------------------------------------------------------------
以上幾個游標(biāo)類型將直接影響到Recordset對象所有的屬性和方法,以下列表說明他們之間的區(qū)別。
-------------------------------------------------------------
Recordset屬性 adOpenForwardOnly adOpenKeyset adOpenDynamic adOpenStatic
-------------------------------------------------------------
AbsolutePage 不支持 不支持 可讀寫 可讀寫
AbsolutePosition 不支持 不支持 可讀寫 可讀寫
ActiveConnection 可讀寫 可讀寫 可讀寫 可讀寫
BOF 只讀 只讀 只讀 只讀
Bookmark 不支持 不支持 可讀寫 可讀寫
CacheSize 可讀寫 可讀寫 可讀寫 可讀寫
CursorLocation 可讀寫 可讀寫 可讀寫 可讀寫
CursorType 可讀寫 可讀寫 可讀寫 可讀寫
EditMode 只讀 只讀 只讀 只讀
EOF 只讀 只讀 只讀 只讀
Filter 可讀寫 可讀寫 可讀寫 可讀寫
LockType 可讀寫 可讀寫 可讀寫 可讀寫
MarshalOptions 可讀寫 可讀寫 可讀寫 可讀寫
MaxRecords 可讀寫 可讀寫 可讀寫 可讀寫
PageCount 不支持 不支持 只讀 只讀
PageSize 可讀寫 可讀寫 可讀寫 可讀寫
RecordCount 不支持 不支持 只讀 只讀
Source 可讀寫 可讀寫 可讀寫 可讀寫
State 只讀 只讀 只讀 只讀
Status 只讀 只讀 只讀 只讀
AddNew 支持 支持 支持 支持
CancelBatch 支持 支持 支持 支持
CancelUpdate 支持 支持 支持 支持
Clone 不支持 不支持
Close 支持 支持 支持 支持
Delete 支持 支持 支持 支持
GetRows 支持 支持 支持 支持
Move 不支持 支持 支持 支持
MoveFirst 支持 支持 支持 支持
MoveLast 不支持 支持 支持 支持
MoveNext 支持 支持 支持 支持
MovePrevious 不支持 支持 支持 支持
NextRecordset 支持 支持 支持 支持
Open 支持 支持 支持 支持
Requery 支持 支持 支持 支持
Resync 不支持 不支持 支持 支持
Supports 支持 支持 支持 支持
Update 支持 支持 支持 支持
UpdateBatch 支持 支持 支持 支持
--------------------------------------------------------------
其中NextRecordset方法并不適用于Microsoft Access數(shù)據(jù)庫。
LockType
Recordset對象Open方法的LockType參數(shù)表示要采用的Lock類型,如果忽略這個參數(shù),那么系統(tǒng)會以Recordset對象的LockType屬性為預(yù)設(shè)值。LockType參數(shù)包含adLockReadOnly、adLockPrssimistic、adLockOptimistic及adLockBatchOptimistic等,分述如下:
-------------------------------------------------------------
常數(shù) 常數(shù)值 說明
--------------------------------------------------------------
adLockReadOnly 1 缺省值,Recordset對象以只讀方式啟動,無法運(yùn)行AddNew、Update及Delete等方法
adLockPrssimistic 2 當(dāng)數(shù)據(jù)源正在更新時,系統(tǒng)會暫時鎖住其他用戶的動作,以保持?jǐn)?shù)據(jù)一致性。
adLockOptimistic 3 當(dāng)數(shù)據(jù)源正在更新時,系統(tǒng)并不會鎖住其他用戶的動作,其他用戶可以對數(shù)據(jù)進(jìn)行增、刪、改的操作。
adLockBatchOptimistic 4 當(dāng)數(shù)據(jù)源正在更新時,其他用戶必須將CursorLocation屬性改為adUdeClientBatch才能對數(shù)據(jù)進(jìn)行增、
刪、改的操作。Top
13 樓ph580(.Net,我喜歡!www.bjcan.com/hengxing)回復(fù)于 2005-12-23 08:21:44 得分 2
這還用在這上面復(fù)制,看我收集的800多個程序文章
www.bjcan.com/hengxing/more.aspTop
14 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 08:23:45 得分 0
怎樣判斷檢測是否checkbox的選擇屬性呢?
選中了會傳回checkbox的value
未選中不會傳回checkbox的value
checkbox全選
選中所有顯示記錄
Top
15 樓ybfqlyq(Rossy|http://blog.ybfq.com)回復(fù)于 2005-12-23 08:30:15 得分 0
轉(zhuǎn)貼經(jīng)典實(shí)用的代碼:
1、關(guān)閉窗口在圖片的連接上寫
javascript:window.close();
提交的圖片連接寫
javascript:document.Form1.submit();
刪除之前出現(xiàn)確認(rèn)對話框:
" ONCLICK="javascript:return confirm('真的要刪除數(shù)據(jù)嗎?')">刪除
2、用JScript彈出提示框然后跳轉(zhuǎn)到指定頁面
Response.Write ""
%>
3、頁面摘入等待。。。。腳本說明:
把如下代碼加入
區(qū)域中document.write("正在載入首頁,請稍等..");
window.clear;
window.location.href="http://www.ybfq.net";
4、在Text直接修改記錄,然后點(diǎn)修改保存記錄
do while not (rs.eof or rs.bof) and count
? ">" size="20" maxlength="50">" size="25" maxlength="30">&page=" onClick="return check()">刪除count=count+1
rs.movenext
loop
%>
5、自動計(jì)算問題:
新浪
百度
中華網(wǎng)
騰訊
Top
16 樓ybfqlyq(Rossy|http://blog.ybfq.com)回復(fù)于 2005-12-23 08:32:22 得分 0
ASP初學(xué)者常犯的幾個錯誤(轉(zhuǎn)貼)
1.記錄集關(guān)閉之前再次打開:
------------------------------------
sql="select * from test"
rs.open sql,conn,1,1
if not rs.eof then
dim myName
myName=rs("name")
end if
sql="select * from myBook"
rs.open sql,conn,1,1
-------------------------------------
解決:在第二次rs.open之前先關(guān)閉 rs.close
或
set rs1=server.createobject
rs1.open sql,conn,1,1
2,用SQL關(guān)鍵字做表名或字段名
-------------------------------------
sql="select * from user"
rs.open sql,conn,1,1
-------------------------------------
user為sql關(guān)鍵字
解決:改為
sql="select * from [user]"
3,用鎖定方式去進(jìn)行update
-------------------------------------
sql="select * from [user]"
rs.open sql,conn,1,1
rs.addnew
或
rs("userName")="aa"
rs.update
-------------------------------------
當(dāng)前記錄集的打開方式為只讀
解決:
改為
rs.open sql,conn,1,3
4,在查詢語句中采用的對比字段值與字段類型不符
-----------------------------------------
sql="select * from [user] where id= " & myID & " "
rs.open sql,conn,1,1
-----------------------------------------
假設(shè)表中設(shè)計(jì)ID為數(shù)字型,那么些時出錯。
解決:
sql="select * from [user] where id=" & myID
5,未檢查變量值而出錯
-----------------------------------------
sql="select * from [user] where id=" & myID
rs.open sql,conn,1,1
-----------------------------------------
假設(shè)myID變量此時值為null,那么sql將成為
sql="select * from [user] where id="
解決:
在前面加上
if isnull(myID) then 出錯提示
6,未檢查變量值類型而出錯
-----------------------------------------
sql="select * from [user] where id=" & myID
rs.open sql,conn,1,1
-----------------------------------------
假設(shè)id為數(shù)字型,myID變量此時值不為null,但為字符,比如myID此時為"aa"
那么sql將成為
sql="select * from [user] where id=aa"
解決:
在前面加上
if isnumeric(myID)=false then 出錯提示
這也可以有效防止 sql injection 漏洞攻擊。
7,由于數(shù)據(jù)庫文件所在目錄的NTFS權(quán)限而引起的 不能更新。數(shù)據(jù)庫或?qū)ο鬄橹蛔x"錯誤。
說明:
WIN2K系統(tǒng)延續(xù)了WINNT系統(tǒng)的NTFS權(quán)限。
對于系統(tǒng)中的文夾都有默認(rèn)的安全設(shè)置。
而通過HTTP對WWW訪問時的系統(tǒng)默認(rèn)用戶是 iusr_計(jì)算機(jī)名 用戶 ,它屬于guest組。
當(dāng)通過HTTP訪問時,可以ASP或JSP,也或是PHP或.NET程序?qū)?shù)據(jù)進(jìn)行修改操作:
比如:
當(dāng)打開某一個文章時,程序設(shè)定,文章的閱讀次數(shù)=原閱讀次數(shù)+1
執(zhí)行
conn.execute("update arts set clicks=clicks+1 where id=n")
語句時,如果 iusr_計(jì)算機(jī)名 用戶沒有對數(shù)據(jù)庫的寫權(quán)限時,就會出錯.
解決方法:
找到數(shù)據(jù)庫所在目錄
右鍵》屬性》安全選項(xiàng)卡》設(shè)置 iusr_計(jì)算機(jī)名 用戶的寫權(quán)限(當(dāng)然,也可以是everyone)Top
17 樓liuph3000()回復(fù)于 2005-12-23 08:33:19 得分 2
其實(shí)就是得到地址欄里"?"以后的字串
var srcc = window.location;
srcc = srcc.toString()
start = srcc.indexOf("?");
end = srcc.length;
Top
18 樓liuph3000()回復(fù)于 2005-12-23 08:34:07 得分 0
window.open 彈出新窗口的命令;
'page.html' 彈出窗口的文件名;
'newwindow' 彈出窗口的名字(不是文件名),非必須,可用空''代替;
height=100 窗口高度;
width=400 窗口寬度;
top=0 窗口距離屏幕上方的象素值;
left=0 窗口距離屏幕左側(cè)的象素值;
toolbar=no 是否顯示工具欄,yes為顯示;
menubar,scrollbars 表示菜單欄和滾動欄。
resizable=no 是否允許改變窗口大小,yes為允許;
location=no 是否顯示地址欄,yes為允許;
status=no 是否顯示狀態(tài)欄內(nèi)的信息(通常是文件已經(jīng)打開),yes為允許;
js腳本結(jié)束
判斷星期幾
yue=month(date())
nian=year(date())
thismon=nian&"-"&yue&"-1"
nextmon=dateadd("m",1,thismon)
tiancount=datediff("d",thismon,nextmon) '本月的天數(shù)
wek= Weekday(date())
select case wek
case 1
response.write "周日"
case 2
response.write "周一"
case 3
response.write "周二"
case 4
response.write "周三"
case 5
response.write "周四"
case 6
response.write "周五"
case 7
response.write "周六"
end select
yue=month(date())
nian=year(date())
thismon=nian&"-"&yue&"-1"
nextmon=dateadd("m",1,thismon)
tiancount=datediff("d",thismon,nextmon) '本月的天數(shù)
dim wek,wekday
wek= Weekday(date())
select case wek
case 1
wekday= "周日"
case 2
wekday= "周一"
case 3
wekday= "周二"
case 4
wekday= "周三"
case 5
wekday= "周四"
case 6
wekday= "周五"
case 7
wekday= "周六"
end select
'response.write "本月共"&tiancount&"天,今天是"&wekday&"
%>
Top
19 樓rimguncheng(asp->.net & vc 沒辦法)回復(fù)于 2005-12-23 08:49:12 得分 2
真是個好東西啊, 謝謝各位啦,, 小弟在這兒 感謝樓主Top
20 樓yangxuhua(楊緒華)回復(fù)于 2005-12-23 08:54:37 得分 2
up,learningTop
21 樓ybfqlyq(Rossy|http://blog.ybfq.com)回復(fù)于 2005-12-23 08:55:56 得分 0
’判斷文件名是否合法
Function isFilename(aFilename)
Dim sErrorStr,iNameLength,i
isFilename=TRUE
sErrorStr=Array("/","/",":","*","?","""","","|")
iNameLength=Len(aFilename)
If iNameLength<1 Or iNameLength=null Then
isFilename=FALSE
Else
For i=0 To 8
If instr(aFilename,sErrorStr(i)) Then
isFilename=FALSE
End If
Next
End If
End Function
’去掉字符串頭尾的連續(xù)的回車和空格
function trimVBcrlf(str)
trimVBcrlf=rtrimVBcrlf(ltrimVBcrlf(str))
end function
’去掉字符串開頭的連續(xù)的回車和空格
function ltrimVBcrlf(str)
dim pos,isBlankChar
pos=1
isBlankChar=true
while isBlankChar
if mid(str,pos,1)=" " then
pos=pos+1
elseif mid(str,pos,2)=VBcrlf then
pos=pos+2
else
isBlankChar=false
end if
wend
ltrimVBcrlf=right(str,len(str)-pos+1)
end function
’去掉字符串末尾的連續(xù)的回車和空格
function rtrimVBcrlf(str)
dim pos,isBlankChar
pos=len(str)
isBlankChar=true
while isBlankChar and pos>=2
if mid(str,pos,1)=" " then
pos=pos-1
elseif mid(str,pos-1,2)=VBcrlf then
pos=pos-2
else
isBlankChar=false
end if
wend
rtrimVBcrlf=rtrim(left(str,pos))
end function
’判斷Email是否有效,返回1表示正確
Function isEmail(aEmail)
Dim iLocat,v,iLength,i,checkletter
If instr(aEmail,"@") = 0 Or instr(aEmail,".") = 0 Then
isEmail=0
EXIT FUNCTION
End If
iLocat=instr(aEmail,"@")
If instr(iLocat,aEmail,".")=0 Or instr(iLocat+1,aEmail,"@")>0 Then
isEmail=0
EXIT FUNCTION
End If
If left(aEmail,1)="." Or right(aEmail,1)="." Or left(aEmail,1)="@" Or right(aEmail,1)="@" Then
isEmail=0
EXIT FUNCTION
End If
v="1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-.@"
iLength=len(aEmail)
For i=1 To iLength
checkletter=mid(aEmail,i,1)
If instr(v,checkletter)=0 Then
isEmail=0
EXIT FUNCTION
End If
Next
isEmail=1
End Function
’測試用:顯示服務(wù)器信息
Sub showServer
Dim name
Response.write "
for each name in request.servervariables
Response.write "
"Response.write "
"&name&""Response.write "
"&request.servervariables(name)&""Response.write "
"next
Response.write "
"End Sub
’測試用:顯示Rs結(jié)果集以及字段名稱
Sub showRs(rs)
Dim strTable,whatever
Response.write "
for each whatever in rs.fields
response.write "
" & whatever.name & ""next
strTable = "
"&rs.GetString(,,"",""," ") &""Response.Write(strTable)
End Sub
’用HTML格式顯示文本
Function txt2Html(str)
if isnull(str) then
txt2Html=""
exit Function
end if
str=Replace(str,chr(34),""")
str=Replace(str,"
str=Replace(str,">",">")
str=Replace(str,chr(13)+chr(10),"
")
str=Replace(str,chr(9)," ")
str=Replace(str," "," ")
txt2Html=str
End Function
’測試用:顯示調(diào)試錯誤信息
Sub showError
Dim sErrMsg
sErrMsg=Err.Source&" "&Err.Description
Response.write "
"&sErrMsg&""Err.clear
End Sub
’顯示文字計(jì)數(shù)器
Sub showCounter
Dim fs,outfile,filename,count
filename=server.mappath("count.txt")
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.fileExists(filename) Then
Set outfile=fs.openTextFile(filename,1)
count=outfile.readline
count=count+1
Response.write "
瀏覽人次:"&count&""outfile.close
Set outfile=fs.CreateTextFile(filename)
outfile.writeline(count)
Else
Set outfile=fs.openTextFile(filename,8,TRUE)
count=0
outfile.writeline(count)
END IF
outfile.close
set fs=nothing
End Sub
%>Top
22 樓xiaogu1234(小古)回復(fù)于 2005-12-23 08:57:06 得分 2
路過,支持ingTop
23 樓meizz(梅花雪)回復(fù)于 2005-12-23 08:57:29 得分 2
嘿嘿,看著上面那個星期幾的判斷,改進(jìn)一下吧。
換一個思路,換一種模式,可能效率會提高很多呀!Top
24 樓meizz(梅花雪)回復(fù)于 2005-12-23 08:59:27 得分 0
回復(fù)人: liuph3000() ( ) 信譽(yù):100 2005-12-23 08:33:00 得分: 0
其實(shí)就是得到地址欄里"?"以后的字串
var srcc = window.location;
srcc = srcc.toString()
start = srcc.indexOf("?");
end = srcc.length;
-------------------------------------------------------
其實(shí)就是得到地址欄里"?"以后的字串
alert(location.search); //這個不是比你的更為簡潔了嗎?
Top
25 樓chzxq(毛毛鼠)回復(fù)于 2005-12-23 09:01:05 得分 2
友情支持Top
26 樓meizz(梅花雪)回復(fù)于 2005-12-23 09:01:13 得分 0
全選與不全選的切換
function All(e, itemName)
{
var aa = document.getElementsByName(itemName);
for (var i=0; i
aa[i].checked = e.checked; //得到那個總控的復(fù)選框的選中狀態(tài)
}
function Item(e, allName)
{
var all = document.getElementsByName(allName)[0];
if(!e.checked) all.checked = false;
else
{
var aa = document.getElementsByName(e.name);
for (var i=0; i
if(!aa[i].checked) return;
all.checked = true;
}
}
Top
27 樓yangxuhua(楊緒華)回復(fù)于 2005-12-23 09:03:11 得分 0
用正則表達(dá)式限制文本類型;
只能輸漢字:οnkeyup="value=value.replace(/[^/u4E00-/u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/u4E00-/u9FA5]/g,''))"
只能輸入數(shù)字:οnkeyup="value=value.replace(/[^/d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"
數(shù)字和英文:οnkeyup="value=value.replace(/[/W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^/d]/g,''))"Top
28 樓lieco()回復(fù)于 2005-12-23 09:07:21 得分 2
這貼肯定要關(guān)注Top
29 樓holder2000(xml)回復(fù)于 2005-12-23 09:10:11 得分 2
30 樓deiphi(面壁思過)回復(fù)于 2005-12-23 09:16:02 得分 2
markTop
31 樓ybfqlyq(Rossy|http://blog.ybfq.com)回復(fù)于 2005-12-23 09:17:38 得分 0
用ASP連接各種數(shù)據(jù)庫的方法
一、ASP的對象存取數(shù)據(jù)庫方法
在ASP中,用來存取數(shù)據(jù)庫的對象統(tǒng)稱ADO(Active Data Objects),主要含有三種對象:
Connection、Recordset 、Command
Connection:負(fù)責(zé)打開或連接數(shù)據(jù)
Recordset:負(fù)責(zé)存取數(shù)據(jù)表
Command:負(fù)責(zé)對數(shù)據(jù)庫執(zhí)行行動查詢命令
二、連接各數(shù)據(jù)庫的驅(qū)動程序
連接各數(shù)據(jù)庫可以使用驅(qū)動程序,也可以使用數(shù)據(jù)源,不過我建議大家使用驅(qū)動程序,因?yàn)槭褂抿?qū)動程序非常
方便、簡單,而使用數(shù)據(jù)源比較麻煩。
ODBC鏈接
適合數(shù)據(jù)庫類型 鏈接方式
access "Driver={microsoft access driver(*.mdb)};dbq=*.mdb;uid=admin;
pwd=pass;"
dBase "Driver={microsoft dbase driver(*.dbf)};driverid=277;dbq=------------;"
Oracle "Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;
pwd=pass;"
MSSQL server "Driver={sql server};server=servername;database=dbname;uid=sa;
pwd=pass;"
MS text "Driver={microsoft text driver(*.txt; *.csv)};dbq=-----;extensions=asc,csv,tab,txt;Persist SecurityInfo=false;"
Visual Foxpro "Driver={microsoft Visual Foxpro driver};sourcetype=DBC;sourceDB=*.dbc;
Exclusive=No;"
MySQL "Driver={mysql};database=yourdatabase;uid=username;pwd=yourpassword;
option=16386;"
OLEDB鏈接
適合的數(shù)據(jù)庫類型 鏈接方式
access "Provider=microsoft.jet.oledb.4.0;data source=your_database_path;user id=admin;
password=pass;"
Oracle "Provider=OraOLEDB.Oracle;data source=dbname;user id=admin;password=pass;"
MS SQL Server "Provider=SQLOLEDB;data source=machinename;initial catalog=dbname;
userid=sa;password=pass;"
MS text "Provider=microsof.jet.oledb.4.0;data source=your_path;Extended Properties′text;
FMT=Delimited′"
而我們在一般情況下使用Access的數(shù)據(jù)庫比較多,在這里我建議大家連接Access數(shù)據(jù)庫使用下面的方法:
dim conn
set conn = server.createobject("adodb.connection")
conn.open = "provider=microsoft.jet.oledb.4.0;" & "data source = " & server.mappath
("../db/bbs.mdb") 其中../db/bbs.mdb是你的數(shù)據(jù)庫存放的相對路徑!如果你的數(shù)據(jù)庫和ASP文件在
同一目錄下,你只要這樣寫就可以了:
dim conn
set conn = server.createobject("adodb.connection")
conn.open = "provider=microsoft.jet.oledb.4.0;" & "data source = " & server.mappath
("bbs.mdb") 有許多初學(xué)者在遇到數(shù)據(jù)庫連接時總是會出問題,然而使用上面的驅(qū)動程序只要
你的數(shù)據(jù)庫路徑選對了就不會出問題了Top
32 樓czq9966(寧錄)(領(lǐng)導(dǎo)咱鬧革命……)回復(fù)于 2005-12-23 09:20:03 得分 2
MarkTop
33 樓ybfqlyq(Rossy|http://blog.ybfq.com)回復(fù)于 2005-12-23 09:20:23 得分 0
一些ASP初學(xué)者常用的代碼
1.獲得系統(tǒng)時間:
2.取得來訪用的IP:
3.獲得系統(tǒng),瀏覽器版本:
window.document.write("版本:"+navigator.appName+navigator.appVersion+" browser.")
4.去除IE混動條:
5.進(jìn)入網(wǎng)站,跳出廣告:
window.open(''http://www.XXXXXX.com'','''',''height=200,width=300,top=0,left=30'');
// -->
6.隨機(jī)數(shù):
N為可改變數(shù)
7.向上混動代碼:
height="207" bgcolor="#FFFF00">hhhhhhhhhhhhhhhhhhh
8.自動關(guān)閉網(wǎng)頁:
本頁10秒后自動關(guān)閉,請注意刷新頁面
9.隨機(jī)背景音樂:
可以修改數(shù)字,限制調(diào)用個數(shù),我這里是60個.
10.自動刷新本頁面:
11.ACCESS數(shù)據(jù)庫連接:
option explicit
dim startime,endtime,conn,connstr,db
startime=timer()
'更改數(shù)據(jù)庫名字
db="data/dvBBS5.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(db)
'如果你的服務(wù)器采用較老版本Access驅(qū)動,請用下面連接方法
'connstr="driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath(db)
conn.Open connstr
function CloseDatabase
Conn.close
Set conn = Nothing
End Function
%>
12.SQL數(shù)據(jù)庫連接:
option explicit
dim startime,endtime,conn,connstr,db
startime=timer()
connstr="driver={SQL Server};server=HUDENQ-N11T33NB;uid=sa;pwd=xsfeihu;database=dvbbs"
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open connstr
function CloseDatabase
Conn.close
Set conn = Nothing
End Function
%>
13.用鍵盤打開網(wǎng)頁代碼:
function ctlent(eventobject)
{
if((event.ctrlKey && window.event.keyCode==13)||(event.altKey && window.event.keyCode==83))
{
window.open('網(wǎng)址','','')
}
}
這里是Ctrl+Enter和Alt+S的代碼 自己查下鍵盤的ASCII碼再換就行!
14.讓層不被控件復(fù)蓋代碼:
> |
15.動網(wǎng)FLASH廣告代碼:
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0
,0" width="468" height="60">
value=high>
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?
P1_Prod_Version=ShockwaveFlash"; type="application/x-shockwave-flash" width="468"
height="60">
16.VBS彈出窗口小代碼:
msgbox"你還沒有注冊或登陸論壇","0","精品論壇"
location.href = "login.asp"
16.使用FSO修改文件特定內(nèi)容的函數(shù)
function FSOchange(filename,Target,String)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FiletempData = objCountFile.ReadAll
objCountFile.Close
FiletempData=Replace(FiletempData,Target,String)
Set objCountFile=objFSO.CreateTextFile(Server.MapPath(filename),True)
objCountFile.Write FiletempData
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function
17.使用FSO讀取文件內(nèi)容的函數(shù)
function FSOFileRead(filename)
Dim objFSO,objCountFile,FiletempData
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objCountFile = objFSO.OpenTextFile(Server.MapPath(filename),1,True)
FSOFileRead = objCountFile.ReadAll
objCountFile.Close
Set objCountFile=Nothing
Set objFSO = Nothing
End Function
18.使用FSO讀取文件某一行的函數(shù)
function FSOlinedit(filename,lineNum)
if linenum < 1 then exit function
dim fso,f,temparray,tempcnt
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
FSOlinedit = temparray(lineNum-1)
end if
end if
end function
19.使用FSO寫文件某一行的函數(shù)
function FSOlinewrite(filename,lineNum,Linecontent)
if linenum < 1 then exit function
dim fso,f,temparray,tempCnt
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
temparray = split(tempcnt,chr(13)&chr(10))
if lineNum>ubound(temparray)+1 then
exit function
else
temparray(lineNum-1) = lineContent
end if
tempcnt = join(temparray,chr(13)&chr(10))
set f = fso.createtextfile(server.mappath(filename),true)
f.write tempcnt
end if
f.close
set f = nothing
end function
20.使用FSO添加文件新行的函數(shù)
function FSOappline(filename,Linecontent)
dim fso,f
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),8,1)
f.write chr(13)&chr(10)&Linecontent
f.close
set f = nothing
end function
21.讀文件最后一行的函數(shù)
function FSOlastline(filename)
dim fso,f,temparray,tempcnt
set fso = server.CreateObject("scripting.filesystemobject")
if not fso.fileExists(server.mappath(filename)) then exit function
set f = fso.opentextfile(server.mappath(filename),1)
if not f.AtEndofStream then
tempcnt = f.readall
f.close
set f = nothing
temparray = split(tempcnt,chr(13)&chr(10))
FSOlastline = temparray(ubound(temparray))
end if
end function
Top
34 樓luluxiang(格格周)回復(fù)于 2005-12-23 09:21:05 得分 2
學(xué)習(xí)。。。謝謝了
還想順便問個問題http://product.zol.com.cn/diy/這種攢機(jī)的東西是怎么做的阿?Top
35 樓czq9966(寧錄)(領(lǐng)導(dǎo)咱鬧革命……)回復(fù)于 2005-12-23 09:21:40 得分 0
支持狗兄Top
36 樓sun00wen00sheng(小太陽)回復(fù)于 2005-12-23 09:34:27 得分 2
ServerVariables 集合檢索預(yù)定的環(huán)境變量。
語法
Request.ServerVariables (server environment variable)
參數(shù)
服務(wù)器環(huán)境變量
指定要檢索的服務(wù)器環(huán)境變量名。可以使用下面列出的值。變量 說明
ALL_HTTP 客戶端發(fā)送的所有 HTTP 標(biāo)題文件。
ALL_RAW 檢索未處理表格中所有的標(biāo)題。ALL_RAW 和 ALL_HTTP 不同,ALL_HTTP 在標(biāo)題文件名前面放置 HTTP_ prefix,并且標(biāo)題名稱總是大寫的。使用 ALL_RAW 時,標(biāo)題名稱和值只在客戶端發(fā)送時才出現(xiàn)。
APPL_MD_PATH 檢索 ISAPI DLL 的 (WAM) Application 的元數(shù)據(jù)庫路徑。
APPL_PHYSICAL_PATH 檢索與元數(shù)據(jù)庫路徑相應(yīng)的物理路徑。IIS 通過將 APPL_MD_PATH 轉(zhuǎn)換為物理(目錄)路徑以返回值。
AUTH_PASSWORD 該值輸入到客戶端的鑒定對話中。只有使用基本鑒定時,該變量才可用。
AUTH_TYPE 這是用戶訪問受保護(hù)的腳本時,服務(wù)器用于檢驗(yàn)用戶的驗(yàn)證方法。
AUTH_USER 未被鑒定的用戶名。
CERT_COOKIE 客戶端驗(yàn)證的唯一 ID,以字符串方式返回。可作為整個客戶端驗(yàn)證的簽字。
CERT_FLAGS 如有客戶端驗(yàn)證,則 bit0 為 1。
如果客戶端驗(yàn)證的驗(yàn)證人無效(不在服務(wù)器承認(rèn)的 CA 列表中),bit1 被設(shè)置為 1。
CERT_ISSUER 用戶驗(yàn)證中的頒布者字段(O=MS,OU=IAS,CN=user name,C=USA)。
CERT_KEYSIZE 安全套接字層連接關(guān)鍵字的位數(shù),如 128。
CERT_SECRETKEYSIZE 服務(wù)器驗(yàn)證私人關(guān)鍵字的位數(shù)。如 1024。
CERT_SERIALNUMBER 用戶驗(yàn)證的序列號字段。
CERT_SERVER_ISSUER 服務(wù)器驗(yàn)證的頒發(fā)者字段。
CERT_SERVER_SUBJECT 服務(wù)器驗(yàn)證的主字段。
CERT_SUBJECT 客戶端驗(yàn)證的主字段。
CONTENT_LENGTH 客戶端發(fā)出內(nèi)容的長度。
CONTENT_TYPE 內(nèi)容的數(shù)據(jù)類型。同附加信息的查詢一起使用,如 HTTP 查詢 GET、 POST 和 PUT。
GATEWAY_INTERFACE 服務(wù)器使用的 CGI 規(guī)格的修訂。格式為 CGI/revision。
HTTP_ HeaderName 存儲在標(biāo)題文件中的值。未列入該表的標(biāo)題文件必須以 HTTP_ 作為前綴,以使 ServerVariables 集合檢索其值。
注意 服務(wù)器將 HeaderName 中的下劃線(_)解釋為實(shí)際標(biāo)題中的破折號。例如,如果您指定 HTTP_MY_HEADER,服務(wù)器將搜索以 MY-HEADER 為名發(fā)送的標(biāo)題文件。
HTTPS 如果請求穿過安全通道(SSL),則返回 ON。如果請求來自非安全通道,則返回 OFF。
HTTPS_KEYSIZE 安全套接字層連接關(guān)鍵字的位數(shù),如 128。
HTTPS_SECRETKEYSIZE 服務(wù)器驗(yàn)證私人關(guān)鍵字的位數(shù)。如 1024。
HTTPS_SERVER_ISSUER 服務(wù)器驗(yàn)證的頒發(fā)者字段。
HTTPS_SERVER_SUBJECT 服務(wù)器驗(yàn)證的主字段。
INSTANCE_ID 文本格式 IIS 實(shí)例的 ID。如果實(shí)例 ID 為 1,則以字符形式出現(xiàn)。使用該變量可以檢索請求所屬的(元數(shù)據(jù)庫中)Web 服務(wù)器實(shí)例的 ID。
INSTANCE_META_PATH 響應(yīng)請求的 IIS 實(shí)例的元數(shù)據(jù)庫路徑。
LOCAL_ADDR 返回接受請求的服務(wù)器地址。如果在綁定多個 IP 地址的多宿主機(jī)器上查找請求所使用的地址時,這條變量非常重要。
LOGON_USER 用戶登錄 Windows NT? 的帳號。
PATH_INFO 客戶端提供的額外路徑信息。可以使用這些虛擬路徑和 PATH_INFO 服務(wù)器變量訪問腳本。如果該信息來自 URL,在到達(dá) CGI 腳本前就已經(jīng)由服務(wù)器解碼了。
PATH_TRANSLATED PATH_INFO 轉(zhuǎn)換后的版本,該變量獲取路徑并進(jìn)行必要的由虛擬至物理的映射。
QUERY_STRING 查詢 HTTP 請求中問號(?)后的信息。
REMOTE_ADDR 發(fā)出請求的遠(yuǎn)程主機(jī)的 IP 地址。
REMOTE_HOST 發(fā)出請求的主機(jī)名稱。如果服務(wù)器無此信息,它將設(shè)置為空的 MOTE_ADDR 變量。
REMOTE_USER 用戶發(fā)送的未映射的用戶名字符串。該名稱是用戶實(shí)際發(fā)送的名稱,與服務(wù)器上驗(yàn)證過濾器修改過后的名稱相對。
REQUEST_METHOD 該方法用于提出請求。相當(dāng)于用于 HTTP 的 GET、HEAD、POST 等等。
SCRIPT_NAME 執(zhí)行腳本的虛擬路徑。用于自引用的 URL。
SERVER_NAME 出現(xiàn)在自引用 UAL 中的服務(wù)器主機(jī)名、DNS 化名或 IP 地址。
SERVER_PORT 發(fā)送請求的端口號。
SERVER_PORT_SECURE 包含 0 或 1 的字符串。如果安全端口處理了請求,則為 1,否則為 0。
SERVER_PROTOCOL 請求信息協(xié)議的名稱和修訂。格式為 protocol/revision 。
SERVER_SOFTWARE 應(yīng)答請求并運(yùn)行網(wǎng)關(guān)的服務(wù)器軟件的名稱和版本。格式為 name/version 。
URL 提供 URL 的基本部分。
注釋
如果客戶端發(fā)送的標(biāo)題文件在上述表格中找不到,可以在調(diào)用 Request.ServerVariables 中給標(biāo)題文件名加上 HTTP_ 的前綴以檢索其值。例如,如果客戶端發(fā)送標(biāo)題文件
SomeNewHeader:SomeNewValue
您可以通過使用下面的語法檢索 SomeNewValue
您可使用重述符以循環(huán)遍歷所有的服務(wù)器變量名。例如,使用下面的腳本打印出所有的服務(wù)器名。
| Server Variable | Value |
示例
下面的例子使用 Request 對象顯示一些服務(wù)器變量。
ALL_HTTP server variable =
CONTENT_LENGTH server variable =
CONTENT_TYPE server variable =
QUERY_STRING server variable =
SERVER_SOFTWARE server variable =
下一個示例使用 ServerVariables 集合將服務(wù)器名插入一個超文本鏈接。
/scripts/MyPage.asp">Link to MyPage.asp
Top
37 樓reddot(reddot)回復(fù)于 2005-12-23 09:49:31 得分 2
窗口在設(shè)定的時間內(nèi)關(guān)閉
首頁 圖片消失
function kick()
{
if(div1.style.pixelTop>-140)
div1.style.pixelTop=div1.style.pixelTop-1
}
function kiss()
{
var p=setInterval("kick()",30);
}
function on_it()
{
div1.style.pixelTop=0;
div1.style.pixelTop=0;
}
自動提交
自動提交 ok
Top
38 樓KimSoft(革命的小酒天天醉-http://blog.csdn.net/kimsoft/)回復(fù)于 2005-12-23 10:12:18 得分 2
絕對潛力帖,幫頂。Top
39 樓MYLiao(醉書生)回復(fù)于 2005-12-23 10:12:33 得分 2
40 樓lisoon(http://www.lisoon.com/FlashRss/)回復(fù)于 2005-12-23 10:23:19 得分 2
我也來貼一個,條型碼code-128 c類編碼,調(diào)用produceHTML(str),code-128 c類的編碼規(guī)則,自己去查。
這個也有php版,是國外的一個人寫的,不過他的php版有一些bug,我從他的php版改來的,寫得亂七八糟的,大家自己整理。
ascii= " !#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_`abcdefghijklmnopqrstuvwxyz{|}~"
dim arr128(106)
arr128(0) = "212222"'c類有自己的規(guī)則,這里的數(shù)字是表示白黑條的寬度
arr128(1) = "222122"
arr128(2) = "222221"
arr128(3) = "121223"
arr128(4) = "121322"
arr128(5) = "131222"
arr128(6) = "122213"
arr128(7) = "122312"
arr128(8) = "132212"
arr128(9) = "221213"
arr128(10) = "221312"
arr128(11) = "231212"
arr128(12) = "112232"
arr128(13) = "122132"
arr128(14) = "122231"
arr128(15) = "113222"
arr128(16) = "123122"
arr128(17) = "123221"'1
arr128(18) = "223211"
arr128(19) = "221132"
arr128(20) = "221231"
arr128(21) = "213212"
arr128(22) = "223112"
arr128(23) = "312131"
arr128(24) = "311222"
arr128(25) = "321122"'9
arr128(26) = "321221"
arr128(27) = "312212"
arr128(28) = "322112"
arr128(29) = "322211"
arr128(30) = "212123"
arr128(31) = "212321"
arr128(32) = "232121"
arr128(33) = "111323"
arr128(34) = "131123"
arr128(35) = "131321"
arr128(36) = "112313"
arr128(37) = "132113"
arr128(38) = "132311"
arr128(39) = "211313"
arr128(40) = "231113"
arr128(41) = "231311"
arr128(42) = "112133"
arr128(43) = "112331"
arr128(44) = "132131"
arr128(45) = "113123"
arr128(46) = "113321"
arr128(47) = "133121"
arr128(48) = "313121"
arr128(49) = "211331"
arr128(50) = "231131"
arr128(51) = "213113"
arr128(52) = "213311"
arr128(53) = "213131"
arr128(54) = "311123"
arr128(55) = "311321"
arr128(56) = "331121"
arr128(57) = "312113"
arr128(58) = "312311"
arr128(59) = "332111"
arr128(60) = "314111"
arr128(61) = "221411"
arr128(62) = "431111"
arr128(63) = "111224"
arr128(64) = "111422"
arr128(65) = "121124"
arr128(66) = "121421"
arr128(67) = "141122"
arr128(68) = "141221"
arr128(69) = "112214"
arr128(70) = "112412"
arr128(71) = "122114"
arr128(72) = "122411"
arr128(73) = "142112"
arr128(74) = "142211"
arr128(75) = "241211"
arr128(76) = "221114"
arr128(77) = "413111"
arr128(78) = "241112"
arr128(79) = "134111"
arr128(80) = "111242"
arr128(81) = "121142"
arr128(82) = "121241"
arr128(83) = "114212"
arr128(84) = "124112"
arr128(85) = "124211"
arr128(86) = "411212"
arr128(87) = "421112"
arr128(88) = "421211"
arr128(89) = "212141"
arr128(90) = "214121"
arr128(91) = "412121"
arr128(92) = "111143"
arr128(93) = "111341"
arr128(94) = "131141"
arr128(95) = "114113"
arr128(96) = "114311"
arr128(97) = "411113"
arr128(98) = "411311"
arr128(99) = "113141"
arr128(100) = "114131"
arr128(101) = "311141"
arr128(102) = "411131"
arr128(103) = "211412"
arr128(104) = "211214"
arr128(105) = "211232"
arr128(106) = "2331112"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function produceArray(intext)
'response.write intext
'response.end
total = 104
' START
ticketArray= "104"
onChar=0
' GO THRU ARRAY GET LETTERS
for z=1 to len(intext)
pos = instr(ascii,mid(intext,z,1))
'/// SKIP, NOT FOUND CHARS,continue loop
'text=text&mid(intext,i,i)&"
"
onChar=onChar+1
ticketArray = ticketArray&","&pos
total = total+( onChar * pos )
next
'response.write text
'response.end()
'/// CHECK CHAR
ticketArray =ticketArray&","&( total mod 103 )
' END
ticketArray=ticketArray&",106"
produceArray=ticketArray
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function produceHTML(givetext)
alignment=0
fheight=30
fwidth=1
bImg="a.jpg"'a與b的寬都為1,a為黑色,b為白色
wImg="b.jpg"
dim color(1)
ticketArray = produceArray(givetext)
ticketArray=split(ticketArray,",")
html ="
| " '/// ARRAY OF IMAGES color(0) = bImg color(1) = wImg ' OUTPUT HTML 'if ( is_array($ticketArray) ) { for each ele in ticketArray bon = 0 info = arr128(int(ele)) for i=1 to len(info) if alignment=0 then html = html&"" else html = html&"" end if if bon=0 then bon=1 else bon=0 end if next next html = html&" |
produceHTML=html
end function
%>Top
41 樓superdullwolf(超級大笨狼,每天要自強(qiáng),MVP)回復(fù)于 2005-12-23 10:56:50 得分 2
呵呵,建議調(diào)整斑竹順序,把活躍的斑竹顯示出來,不活躍的隱藏。Top
42 樓loveme2000ok(* °¤ °*)回復(fù)于 2005-12-23 11:13:25 得分 2
ASP操作Excel技術(shù)總結(jié)
目錄
一、 環(huán)境配置
二、 ASP對Excel的基本操作
三、 ASP操作Excel生成數(shù)據(jù)表
四、 ASP操作Excel生成Chart圖
五、 服務(wù)器端Excel文件瀏覽、下載、刪除方案
六、 附錄
正文
一、 環(huán)境配置
服務(wù)器端的環(huán)境配置從參考資料上看,微軟系列的配置應(yīng)該都行,即:
1.Win9x+PWS+Office
2.Win2000 Professional+PWS+Office
3.Win2000 Server+IIS+Office
目前筆者測試成功的環(huán)境是后二者。Office的版本沒有特殊要求,考慮到客戶機(jī)配置的不確定性和下兼容特性,建議服務(wù)器端Office版本不要太高,以防止客戶機(jī)下載后無法正確顯示。
服務(wù)器端環(huán)境配置還有兩個偶然的發(fā)現(xiàn)是:
1. 筆者開發(fā)機(jī)器上原來裝有金山的WPS2002,結(jié)果Excel對象創(chuàng)建始終出現(xiàn)問題,卸載WPS2002后,錯誤消失。
2. 筆者開發(fā)ASP代碼喜歡用FrontPage,結(jié)果發(fā)現(xiàn)如果FrontPage打開(服務(wù)器端),對象創(chuàng)建出現(xiàn)不穩(wěn)定現(xiàn)象,時而成功時而不成功。擴(kuò)展考察后發(fā)現(xiàn),Office系列的軟件如果在服務(wù)器端運(yùn)行,則Excel對象的創(chuàng)建很難成功。
服務(wù)器端還必須要設(shè)置的一點(diǎn)是COM組件的操作權(quán)限。在命令行鍵入“DCOMCNFG”,則進(jìn)入COM組件配置界面,選擇Microsoft Excel后點(diǎn)擊屬性按鈕,將三個單選項(xiàng)一律選擇自定義,編輯中將Everyone加入所有權(quán)限。保存完畢后重新啟動服務(wù)器。
客戶端的環(huán)境配置沒發(fā)現(xiàn)什么特別講究的地方,只要裝有Office和IE即可,版本通用的好象都可以。
二、 ASP對Excel的基本操作
1、 建立Excel對象
set objExcelApp = CreateObject("Excel.Application")
objExcelApp.DisplayAlerts = false 不顯示警告
objExcelApp.Application.Visible = false 不顯示界面
2、 新建Excel文件
objExcelApp.WorkBooks.add
set objExcelBook = objExcelApp.ActiveWorkBook
set objExcelSheets = objExcelBook.Worksheets
set objExcelSheet = objExcelBook.Sheets(1)
3、 讀取已有Excel文件
strAddr = Server.MapPath(".")
objExcelApp.WorkBooks.Open(strAddr & "/Templet/Table.xls")
set objExcelBook = objExcelApp.ActiveWorkBook
set objExcelSheets = objExcelBook.Worksheets
set objExcelSheet = objExcelBook.Sheets(1)
4、 另存Excel文件
objExcelBook.SaveAs strAddr & "/Temp/Table.xls"
5、 保存Excel文件
objExcelBook.Save (筆者測試時保存成功,頁面報(bào)錯。)
6、 退出Excel操作
objExcelApp.Quit 一定要退出
set objExcelApp = Nothing
三、 ASP操作Excel生成數(shù)據(jù)表
1、 在一個范圍內(nèi)插入數(shù)據(jù)
objExcelSheet.Range("B3:k3").Value = Array("67", "87", "5", "9", "7", "45", "45", "54", "54", "10")
2、 在一個單元格內(nèi)插入數(shù)據(jù)
objExcelSheet.Cells(3,1).Value="Internet Explorer"
3、 選中一個范圍
4、 單元格左邊畫粗線條
5、 單元格右邊畫粗線條
6、 單元格上邊畫粗線條
7、 單元格下邊畫粗線條
8、 單元格設(shè)定背景色
9、 合并單元格
10、 插入行
11、 插入列
四、 ASP操作Excel生成Chart圖
1、 創(chuàng)建Chart圖
objExcelApp.Charts.Add
2、 設(shè)定Chart圖種類
objExcelApp.ActiveChart.ChartType = 97
注:二維折線圖,4;二維餅圖,5;二維柱形圖,51
3、 設(shè)定Chart圖標(biāo)題
objExcelApp.ActiveChart.HasTitle = True
objExcelApp.ActiveChart.ChartTitle.Text = "A test Chart"
4、 通過表格數(shù)據(jù)設(shè)定圖形
objExcelApp.ActiveChart.SetSourceData objExcelSheet.Range("A1:k5"),1
5、 直接設(shè)定圖形數(shù)據(jù)(推薦)
objExcelApp.ActiveChart.SeriesCollection.NewSeries
objExcelApp.ActiveChart.SeriesCollection(1).Name = "=""333"""
objExcelApp.ActiveChart.SeriesCollection(1).Values = "="
6、 綁定Chart圖
objExcelApp.ActiveChart.Location 1
7、 顯示數(shù)據(jù)表
objExcelApp.ActiveChart.HasDataTable = True
8、 顯示圖例
objExcelApp.ActiveChart.DataTable.ShowLegendKey = True
五、 服務(wù)器端Excel文件瀏覽、下載、刪除方案
瀏覽的解決方法很多,“Location.href=”,“Navigate”,“Response.Redirect”都可以實(shí)現(xiàn),建議用客戶端的方法,原因是給服務(wù)器更多的時間生成Excel文件。
下載的實(shí)現(xiàn)要麻煩一些。用網(wǎng)上現(xiàn)成的服務(wù)器端下載組件或自己定制開發(fā)一個組件是比較好的方案。另外一種方法是在客戶端操作Excel組件,由客戶端操作服務(wù)器端Excel文件另存至客戶端。這種方法要求客戶端開放不安全ActiveX控件的操作權(quán)限,考慮到通知每個客戶將服務(wù)器設(shè)置為可信站點(diǎn)的麻煩程度建議還是用第一個方法比較省事。
刪除方案由三部分組成:
A: 同一用戶生成的Excel文件用同一個文件名,文件名可用用戶ID號或SessionID號等可確信不重復(fù)字符串組成。這樣新文件生成時自動覆蓋上一文件。
B: 在Global.asa文件中設(shè)置Session_onEnd事件激發(fā)時,刪除這個用戶的Excel暫存文件。
C: 在Global.asa文件中設(shè)置Application_onStart事件激發(fā)時,刪除暫存目錄下的所有文件。
注:建議目錄結(jié)構(gòu) /Src 代碼目錄 /Templet 模板目錄 /Temp 暫存目錄
六、 附錄
出錯時Excel出現(xiàn)的死進(jìn)程出現(xiàn)是一件很頭疼的事情。在每個文件前加上“On Error Resume Next”將有助于改善這種情況,因?yàn)樗鼤还芪募欠癞a(chǎn)生錯誤都堅(jiān)持執(zhí)行到“Application.Quit”,保證每次程序執(zhí)行完不留下死進(jìn)程。
Top
43 樓loveme2000ok(* °¤ °*)回復(fù)于 2005-12-23 11:13:40 得分 0
評論
# re: ASP操作Excel技術(shù)總結(jié)
這個程序一共由三個文件構(gòu)成,第一個文件的文件名為:toexcel.asp是主文件,內(nèi)容如下:
'前面是和來鏈接到數(shù)據(jù)庫,請自行書寫相關(guān)語句,此處略過
sql="select * from [tx_use]" '這里是要輸出EXCEL的查詢語句,如 "SESECT * FORM CAI WHERE 性別='女'"
filename="excel.xls" ' 要輸出的EXCEL文件的文件名, 你只要改以上兩句就行了,其它的都不要改.
'你只要修改以上兩變量就行了.其它的我都做好了.
call toexcel(FILENAME,sql)
set conn=nothing
function ReadText(FileName) '這是一個用于讀出文件的函數(shù)
set adf=server.CreateObject("Adodb.Stream")
with adf
.Type=2
.LineSeparator=10
.Open
.LoadFromFile (server.MapPath(FileName))
.Charset="GB2312"
.Position=2
ReadText=.ReadText
.Cancel()
.Close()
end with
set ads=nothing
end function
sub SaveText(FileName,Data) '這是一個用于寫文件的函數(shù)
set fs= createobject("scripting.filesystemobject")
set ts=fs.createtextfile(server.MapPath(FileName),true)
ts.writeline(data)
ts.close
set ts=nothing
set fs=nothing
end sub
sub toexcel(filename,sql) '這是一個根據(jù)SQL語句和FILENAME生成EXCEL文件
Set rs=Server.CreateObject("ADODB.RecordSet")
rs.Open sql,conn,1,3
TOEXCELLR="
set myfield=rs.fields
dim fieldname(50)
for i=0 to myfield.count-1
toexcellr=toexcellr&"
"&MYFIELD(I).NAME&""fieldname(i)=myfield(i).name
if myfield(i).type=135 then datename=datename&myfield(i).name&","
next
toexcellr=toexcellr&"
"do while not rs.eof
toexcellr=toexcellr&"
"for i=0 to myfield.count-1
if instr(datename,fieldname(i)&",")<>0 then
if not isnull(rs(fieldname(i))) then
TOEXCELLR=TOEXCELLR&"
"&formatdatetime(rs(fieldname(i)),2)&"
"else
TOEXCELLR=TOEXCELLR&"
"end if
else
TOEXCELLR=TOEXCELLR&"
"&rs(fieldname(i))&""end if
next
toexcellr=toexcellr&"
"rs.movenext
loop
toexcellr=toexcellr&"
"tou=readtext("tou.txt")
di=readtext("di.txt")
toexcellr=tou&toexcellr&di
call savetext(filename,toexcellr)
end sub
%>
正在生成EXLCE文件正在生成EXLCE文件....
**************第二個文件名為:di.txt 內(nèi)容如下:
************第三個文件的文件名為:tou.TXT 內(nèi)容如下:
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns="http://www.w3.org/TR/REC-html40">
44 樓loveme2000ok(* °¤ °*)回復(fù)于 2005-12-23 11:14:28 得分 0
如何在ASP中實(shí)現(xiàn)網(wǎng)絡(luò)打印功能
使用到的技術(shù):
ASP,WSH,VBScript
文件ASPPrint.asp代碼如下:
Option Explicit
Dim strSubmit 'Form中用來保存提交按鈕的值
Dim strPrinterPath 'Form中保存網(wǎng)絡(luò)打印機(jī)路徑的值
Dim strUsername 'Form中用戶名的值
Dim strPassword 'Form中密碼的值
Dim strMessage 'Form打印內(nèi)容的值
Dim objFS 'VBScript中的文件系統(tǒng)對象
Dim objWSHNet 'WSH中的網(wǎng)絡(luò)對象
Dim objPrinter '打印對象
strSubmit = Request.Form("Submit")
%>
If strSubmit = "" Then
%>
注意的是:
由于我是演示起見,其中有關(guān)NT的帳號和密碼都是使用了不加密的手段在
ASP中傳遞的
真正的運(yùn)用中應(yīng)該對該登錄過程進(jìn)行安全處理。
=1>
網(wǎng)絡(luò)打印機(jī)路徑:e=printerpath
value="//< Domain >/< Printer >">
登錄帳號:sername
value="">
登錄口令:name=password>
請輸入你想打印的文字:name=message>
id=submit name=submit>
當(dāng)以上信息被提交后,就可以按照下面的代碼進(jìn)行打印了。
Else
' 從form中取得響應(yīng)信息。
strPrinterPath = Request.Form("printerpath")
strUsername = Request.Form("username")
strPassword = Request.Form("password")
strMessage = Request.Form("message")
We will now use the VBScript FileSystemObject object and the WSH Net
work object. The Network object will
give us the methods we need to open a printer connection, and the Fi
leSystemObject will allow us to stream our
output to the printer. We create these objects in the following code
example:
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objWSHNet = CreateObject("WScript.Network")
' 使用WSH連接網(wǎng)絡(luò)打印機(jī)
objWSHNet.AddPrinterConnection "LPT1", strPrinterPath, False, str
Username, strPassword
' 使用文件系統(tǒng)對象將打印設(shè)備作為一個文件使用
Set objPrinter = objFS.CreateTextFile("LPT1:", True)
' 給打印設(shè)備送出文本
objPrinter.Write(strMessage)
'關(guān)閉打印設(shè)備對象并進(jìn)行錯誤陷阱處理
On Error Resume Next
objPrinter.Close
' 如果發(fā)生錯誤,關(guān)閉打印連接,并輸出錯誤信息
If Err Then
Response.Write ("Error # " & CStr(Err.Number) & " " & Err.Desc
ription)
Err.Clear
Else
' 操作成功,輸出確認(rèn)信息
Response.Write("
")Response.Write("
ACING=1 CELLPADDING=1>")
Response.Write("
打印消息送出:")
Response.Write("
" & strMessage & "")Response.Write("
網(wǎng)絡(luò)打印機(jī)路徑:>")
Response.Write("
" & strPrinterPath & ">")
Response.Write("
登錄帳號:")Response.Write("
" & strUsername & "")Response.Write("
")Response.Write("
")End If
' 取消打印連接
objWSHNet.RemovePrinterConnection "LPT1:"
Set objWSHNet = Nothing
Set objFS = Nothing
Set objPrinter = Nothing
End If
%>
Top
45 樓zwrtv(蝙蝠)回復(fù)于 2005-12-23 11:19:42 得分 2
學(xué)習(xí)下Top
46 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 11:20:20 得分 0
response_buffer.asp
a
效果:
①.當(dāng)關(guān)閉IIS的緩沖功能,訪問該頁面時出錯
a
答復(fù)對象 錯誤 'ASP 0156 : 80004005'
頭錯
/course/response_buffer.asp,行3
HTTP 頭已經(jīng)寫入到 客戶瀏覽器。任何 HTTP 頭的修改必須在寫入頁內(nèi)容之前。
②.當(dāng)關(guān)閉IIS的緩沖功能,去掉文件第一行的注釋,則頁面重定向成功
③.當(dāng)打開IIS的緩沖功能,無論是否去掉文件第一行的注釋,頁面重定向都成功
Top
47 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 11:22:12 得分 0
問題:如何保護(hù)自己的ASP源代碼不泄露?
答:下載微軟的windows script encoder,對ASP的腳本和客戶端javascript、vbscript腳本進(jìn)行加密。客戶端腳本加密后,只有ie5以上的版本才能執(zhí)行,服務(wù)器端腳本加密后,只有服務(wù)器上安裝有script engine 5(裝ie5即可)才能解釋執(zhí)行。
問題:為什么global.asa文件總是不起作用?
答:只有把global.asa文件放在web發(fā)布目錄某個站點(diǎn)的根目錄下它才有效,放在發(fā)布目錄的某個子目錄下不起作用。另外,也可以使用iis4的internet service manager把某個子目錄設(shè)置為站點(diǎn)。
問題:為什么ASP文件總不解釋執(zhí)行?
答:在iis服務(wù)器上沒有給ASP文件以腳本解釋的權(quán)限,所以ASP文件沒有被web服務(wù)器作為腳本代碼進(jìn)行解釋執(zhí)行,而被當(dāng)成一般頁面文件了。建議在web發(fā)布目錄中建立一個ASP目錄,把所有ASP文件存放在此目錄下,把ASP目錄賦予腳本解釋權(quán)限。
問題:ASP文件中使用response.redirect(url)時導(dǎo)致錯誤“the http headers are already written to the client browser. any http header modifications must be made before writing page content”,請問如何解決?
答:此錯誤為http標(biāo)題在寫入頁內(nèi)容之后,寫到了客戶瀏覽器中。任何http標(biāo)題的修改必須在寫入頁內(nèi)容之前進(jìn)行,解決的方法為在ASP文件最開頭加入response.buffer = true,在文件的結(jié)尾加入response.flush。
問題:為什么session有時候會消失?
答:session很像臨時的cookie,只是其信息保存在服務(wù)器上(客戶機(jī)上保存的是sessionid)。session變量消失有幾種可能,如:使用者的瀏覽器不接受cookie,因?yàn)閟ession依賴于cookie才能跟蹤用戶;session在一段時間后過期了,缺省為20分鐘,如果希望更改,可以通過設(shè)置microsoft management console的web directory→properties→virtual directory→application settings→configuration→app options→session timeout選項(xiàng)來改變session的超時時間,也可以在ASP腳本中設(shè)定,如session.timeout=60,可設(shè)定超時時間為60分鐘。
問題:怎樣才能知道訪問者的一些信息?
答:通過request.servervariables("http—user—agent")獲得訪問者瀏覽器的類型;request.servervariables("remote—addr")可獲得訪問者的ip地址;而訪問者的語言環(huán)境可通過request.servervariables("http—accept—language")來獲得。
問題:怎樣才能將query string從一個ASP文件傳送到另一個ASP文件?
答:前一個ASP文件加入下列代碼:response.redirect("second.ASP?"&request.servervariables("query—string"))即可。
問題:ASP中如何控制cookies?
答:若想寫入cookies可用:response.cookies("待寫入的coookies名稱")=待寫入數(shù)據(jù)。讀取cookies則使用:讀取數(shù)據(jù)=request.cookies("待讀的cookies名稱")。
注意,寫入cookies的response.cookies程序段必須放在〈html〉標(biāo)記之前,且不可以有任何的其它html代碼。另外,cookies中必須使用expires設(shè)定有效期,cookies才能真正地寫入客戶端硬盤中,否則只是臨時的。
問題:怎樣實(shí)現(xiàn)用ASP發(fā)送郵件?
答:用戶需裝上windows nt option pack的smtp service功能。實(shí)現(xiàn)代碼如下:
〈%
set mail = server.createobject("cdonts.newmail")
mail.to ="abc@xxx.com"
mail.from ="yourmail@xxx.com"
mail.subject ="主題"
mail.body ="e-mail內(nèi)容"
mail.send
%〉
問題:ASP與數(shù)據(jù)庫連接一定要在服務(wù)器端設(shè)置dsn嗎?
答:不一定,ASP與服務(wù)器的數(shù)據(jù)庫連接有兩種方法,一種為通過dsn建立連接,另一種不用dsn建立連接。通過dsn連接數(shù)據(jù)庫需要服務(wù)器的系統(tǒng)管理員在服務(wù)器的控制面板中的odbc中設(shè)置一個dsn。如果沒有在服務(wù)器上設(shè)置dsn,只要知道數(shù)據(jù)庫文件名(比如access、paradox、foxpro的數(shù)據(jù)庫)或者數(shù)據(jù)源名(如sqlserver的數(shù)據(jù)庫)就可以訪問數(shù)據(jù)庫,直接提供連接所需的參數(shù)即可。
連接代碼如下:
set conn=server.createobject("adodb.connection")
connpath="dbq="&server.mappath("yourtable.mdb")
conn.open"driver={microsoft access driver (.mdb)};"&connpath
set rs=conn.execute("selectfrom authors")
問題:如何從一頁到另一頁傳遞變量?
答:用hidden表單類型來傳遞變量。
〈form method="post"action="mynextpage.ASP"〉
〈% for each item in request.form %〉
〈input namee="〈%=item%〉"type="hidden"
value="〈%=server.htmlencode(request.form(item)) %〉"〉
〈% next %〉
〈/form〉
用session來保存變量。
〈%session("bh")= request.form ("bh")%〉
用querystring保存變量。
〈a herf="action.ASP?bh=10"〉查詢〈/a〉
〈%request. querystring ("bh")%〉
問題:如何用ASP實(shí)現(xiàn)在線人數(shù)統(tǒng)計(jì)?
答:在線人數(shù)是指一個時段內(nèi)的訪客人數(shù)統(tǒng)計(jì),時間的長短是由設(shè)計(jì)者設(shè)定的。
在這個時段內(nèi),各個不同ip訪問本站點(diǎn)的總數(shù),就是當(dāng)前的線上人數(shù)。在ASP中,使用session對象來實(shí)現(xiàn)統(tǒng)計(jì),實(shí)現(xiàn)代碼如下:
golobal.asa文件
〈script language="vbscript"runat="server"〉
sub session—onstart
application("online")=application("online")+1
end sub
sub session—onend
application("online")=application("online")-1
end sub
sub application—onstard
application("online")=0
end sub
sub application—onend
application("online")=0
end sub
〈/script〉
online.ASP文件內(nèi)容
〈% tmp=application("online")
tmp=cstr(tmp)
dim disp(20)
dim images(20)
dbbits=len(tmp)
for i= 1 to dbbits
disp(i)=left(right(tmp,i),i-(i-1))
next
for i=dbbits to 1 step -1
images(i)="〈img src="&"http://xxxx.com.cn/pic"&"/"&disp(i)&".gif〉"
response.write"document.write(′"&images(i)&"′);"
next %〉
問題:ASP程序運(yùn)行的時間如何計(jì)算?
答:確定ASP程序的執(zhí)行時間的代碼如下所示:
〈%
dim t1,t2
t1=now()
′被檢測的ASP代碼
t2=now()
response.write"運(yùn)行這段ASP代碼用了"&cstr(cdbl((t2-t1)*24*60*60))&"秒"
%〉
Top
48 樓tshuxing()回復(fù)于 2005-12-23 11:23:09 得分 2
一個操作讀寫已存在Excel文件的例子
Set xlApp = Server.CreateObject("Excel.Application")
strSource=FilePath & "Test.xls"'打開一個已經(jīng)存在的test.xls文件,filepath為物理絕對路徑
xlApp.Workbooks.Open(strSource)
Set xlbook = xlApp.ActiveWorkBook '打開book
Set xlsheet = xlbook.Worksheets(1) '打開其中的一個sheet
xlsheet.cells(1,1).value="Test" '通過設(shè)置cell(i,j)里面的i,j來訪問sheet里面任意一個cell
xlbook.Save '保存該excel文件
xlbook.Saveas FilePath & "Test2.xls" '另存一個文件
Set xlsheet=nothing '一定要關(guān)閉,否則以后會一直存在一個無法釋放的excel進(jìn)程
Set xlbook=nothing
xlApp.quit
asp運(yùn)行端的一些設(shè)置
1Excel文件所在的路徑目錄,要讓IUSER_即asp運(yùn)行的用戶有讀寫權(quán)限,否則
會報(bào)錯。
2服務(wù)器端還必須要設(shè)置COM組件的操作權(quán)限。在命令行鍵入“DCOMCNFG”,
進(jìn)入COM組件配置界面,選擇Microsoft Excel后點(diǎn)擊屬性按鈕,將三個單選
項(xiàng)一律選擇自定義,編輯中將Everyone加入所有權(quán)限。保存完畢后重新啟動
服務(wù)器。
Top
49 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 11:23:21 得分 0
如何使用事務(wù)處理、存儲過程和視圖?
⑴.使用存儲過程
①.定義好存儲過程
CREATE PROCEDURE [output_1]
@sid int output
AS
set @sid=2
CREATE PROCEDURE [return_1]
(@user_name varchar(40),@password varchar(20))
AS
if exists(select id from user_info where user_name=@user_name and password=@password)
return 1
else
return 0
CREATE PROCEDURE [user_info_1]
(@user_name varchar(40),@password varchar(20))
AS
select id from user_info where user_name=@user_name and password=@password
CREATE PROCEDURE [user_info_2]
(@user_name varchar(40),@password varchar(20))
AS
SET XACT_ABORT ON
BEGIN TRANSACTION
delete from user_info where user_name=@user_name and password=@password
COMMIT TRANSACTION
SET XACT_ABORT OFF
CREATE PROCEDURE [user_info_3] AS
select * from user_info
②.在Asp中調(diào)用
use_proc.asp
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "course_dsn","course_user","course_password"
'使用recordset調(diào)用帶兩個輸入?yún)?shù)和返回紀(jì)錄集的存儲過程
'CREATE PROCEDURE [user_info_1]
'(@user_name varchar(40),@password varchar(20))
'AS
'select id from user_info where user_name=@user_name and password=@password
response.write "普通的調(diào)用方法:
"
set rs=server.createobject("adodb.recordset")
sql="user_info_1 '"&request.querystring("user_name")&"','"&request.querystring("password")&"'"
rs.open sql,conn,1,1
response.write rs("id")&"
"
rs.close
'使用recordset調(diào)用無輸入?yún)?shù),返回紀(jì)錄集的存儲過程,可以使用recordcount等屬性
'CREATE PROCEDURE [user_info_3] AS
'select * from user_info
response.write "
返回紀(jì)錄集,可以使用recordcount等屬性:"
sql="exec user_info_3"
rs.open sql,conn,1,1
for i=1 to rs.recordcount
response.write "
"&rs("user_name")
rs.movenext
next
rs.close
set rs=nothing
'使用command調(diào)用帶輸出參數(shù)的存儲過程
'CREATE PROCEDURE [output_1]
'@sid int output
'AS
'set @sid=2
response.write "
調(diào)用帶輸出參數(shù)的存儲過程:
"
set cmd=server.createobject("adodb.command")
cmd.activeconnection=conn
cmd.commandtext = "output_1"
cmd.parameters.append cmd.createparameter("@sid",adinteger,adparamoutput)
cmd("@sid")=10
cmd.execute()
bbb=cmd("@sid")
response.write bbb&"
"
set cmd=nothing
'使用command調(diào)用帶兩個輸入?yún)?shù)和返回值的存儲過程
'CREATE PROCEDURE [return_1]
'(@user_name varchar(40))
'AS
'if exists(select id from user_info where user_name=@user_name)
'return 1
'else
'return 0
response.write "
調(diào)用帶兩個輸入?yún)?shù)和返回值的存儲過程:
"
set cmd=server.createobject("adodb.command")
cmd.activeconnection=conn
cmd.commandtype = adcmdstoredproc
cmd.commandtext = "return_1"
cmd.parameters.append cmd.createparameter("@return_value",adinteger,adparamreturnvalue)
cmd.parameters.append cmd.createparameter("@user_name",advarchar,adparaminput,40)
cmd.parameters.append cmd.createparameter("@password",advarchar,adparaminput,20)
cmd("@user_name")="tuth"
cmd("@password")="yyuyu"
cmd.execute()
rrr=cmd("@return_value")
response.write rrr
set cmd=nothing
conn.close
set conn=nothing
%>
效果:
訪問http://10.1.43.238/course/use_proc.asp?user_name=ahyi&password=ttt時,出現(xiàn)如下
普通的調(diào)用方法:
12
返回紀(jì)錄集,可以使用recordcount等屬性:
ahyi
tet
tuth
調(diào)用帶輸出參數(shù)的存儲過程:
2
調(diào)用帶兩個輸入?yún)?shù)和返回值的存儲過程:
1
注意:若存儲過程無參數(shù),則調(diào)用的sql語句直接為存儲過程名,一個參數(shù)為“存儲過程名 參數(shù)”,若是多個參數(shù),則“存儲過程名 參數(shù)1,參數(shù)2,……,參數(shù)n”;如果在sql語句中加入exec,則在返回的記錄集中可以使用recordcount等屬性;如果想獲得存儲過程的返回值或輸出參數(shù),可以使用command對象。
⑵.使用事務(wù)處理
①.Asp內(nèi)嵌的事務(wù)支持
例子:
use_transaction_1.asp
'Asp中使用事務(wù)
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "course_dsn","course_user","course_password"
conn.begintrans '開始事務(wù)
sql="delete from user_info"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,3
if conn.errors.count>0 then '有錯誤發(fā)生
conn.rollbacktrans '回滾
set rs=nothing
conn.close
set conn=nothing
response.write "交易失敗,回滾至修改前的狀態(tài)!"
response.end
else
conn.committrans '提交事務(wù)
set rs=nothing
conn.close
set conn=nothing
response.write "交易成功!"
response.end
end if
%>
②.數(shù)據(jù)庫級的事務(wù)
i.創(chuàng)建存儲過程
CREATE PROCEDURE [user_info_2]
(@user_name varchar(40),@password varchar(20))
AS
SET XACT_ABORT ON
BEGIN TRANSACTION
delete from user_info where user_name=@user_name and password=@password
COMMIT TRANSACTION
SET XACT_ABORT OFF
ii.在Asp中調(diào)用
use_transaction_2.asp
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "course_dsn","course_user","course_password"
sql="user_info_2 '"&request.querystring("user_name")&"','"&request.querystring("password")&"'"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
set rs=nothing
conn.close
set conn=nothing
%>
討論:兩種方式的優(yōu)劣?
⑶.使用視圖
在數(shù)據(jù)庫中定義好視圖之后,在Asp中如同使用一個表一樣來使用視圖Top
50 樓MONOSON(*黑色幻想*)回復(fù)于 2005-12-23 11:24:37 得分 2
學(xué)習(xí)中
等結(jié)貼后收藏,呵呵~~Top
51 樓chinastorm(JOBS.CN)回復(fù)于 2005-12-23 11:26:01 得分 2
先收藏了Top
52 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 11:47:25 得分 0
各類型數(shù)據(jù)的導(dǎo)入與導(dǎo)出:
******* 導(dǎo)出到excel
EXEC master..xp_cmdshell 'bcp SettleDB.dbo.shanghu out c:/temp1.xls -c -q -S"GNETDATA/GNETDATA" -U"sa" -P""'
/*********** 導(dǎo)入Excel
select * from openrowset('MicroSoft.Jet.OleDB.4.0',
'Excel 5.0;HDR=yes;Database=c:/test.xls',sheet1$)
--------------------------------------------------------
SELECT *
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:/test.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions
SELECT cast(cast(科目編號 as numeric(10,2)) as nvarchar(255))+' ' 轉(zhuǎn)換后的別名
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:/test.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions
/** 導(dǎo)入文本文件
EXEC master..xp_cmdshell 'bcp "dbname..tablename" in c:/DT.txt -c -Sservername -Usa -Ppassword'
/** 導(dǎo)出文本文件
EXEC master..xp_cmdshell 'bcp "dbname..tablename" out c:/DT.txt -c -Sservername -Usa -Ppassword'
或
EXEC master..xp_cmdshell 'bcp "Select * from dbname..tablename" queryout c:/DT.txt -c -Sservername -Usa -Ppassword'
導(dǎo)出到TXT文本,用逗號分開
exec master..xp_cmdshell 'bcp "庫名..表名" out "d:/tt.txt" -c -t ,-U sa -P password'
BULK INSERT 庫名..表名
FROM 'c:/test.txt'
WITH (
FIELDTERMINATOR = ';',
ROWTERMINATOR = '/n'
)
--/* dBase IV文件
select * from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'dBase IV;HDR=NO;IMEX=2;DATABASE=C:/','select * from [客戶資料4.dbf]')
--*/
--/* dBase III文件
select * from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'dBase III;HDR=NO;IMEX=2;DATABASE=C:/','select * from [客戶資料3.dbf]')
--*/
--/* FoxPro 數(shù)據(jù)庫
select * from openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;SourceDB=c:/',
'select * from [aa.DBF]')
--*/
/**************導(dǎo)入DBF文件****************/
select * from openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;
SourceDB=e:/VFP98/data;
SourceType=DBF',
'select * from customer where country != "USA" order by country')
go
/***************** 導(dǎo)出到DBF ***************/
如果要導(dǎo)出數(shù)據(jù)到已經(jīng)生成結(jié)構(gòu)(即現(xiàn)存的)FOXPRO表中,可以直接用下面的SQL語句
insert into openrowset('MSDASQL',
'Driver=Microsoft Visual FoxPro Driver;SourceType=DBF;SourceDB=c:/',
'select * from [aa.DBF]')
select * from 表
說明:
SourceDB=c:/ 指定foxpro表所在的文件夾
aa.DBF 指定foxpro表的文件名.
/*************導(dǎo)出到Access********************/
insert into openrowset('Microsoft.Jet.OLEDB.4.0',
'x:/A.mdb';'admin';'',A表) select * from 數(shù)據(jù)庫名..B表
/*************導(dǎo)入Access********************/
insert into B表 selet * from openrowset('Microsoft.Jet.OLEDB.4.0',
'x:/A.mdb';'admin';'',A表)
********************* 導(dǎo)入 xml 文件
DECLARE @idoc int
DECLARE @doc varchar(1000)
--sample XML document
SET @doc ='
Customer was very satisfied
Important
Happy Customer.
'
-- Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
-- Execute a SELECT statement using OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/root/Customer/Order', 1)
WITH (oid char(5),
amount float,
comment ntext 'text()')
EXEC sp_xml_removedocument @idoc
鄒健的
/********************導(dǎo)整個數(shù)據(jù)庫*********************************************/
用bcp實(shí)現(xiàn)的存儲過程
/*
實(shí)現(xiàn)數(shù)據(jù)導(dǎo)入/導(dǎo)出的存儲過程
根據(jù)不同的參數(shù),可以實(shí)現(xiàn)導(dǎo)入/導(dǎo)出整個數(shù)據(jù)庫/單個表
調(diào)用示例:
--導(dǎo)出調(diào)用示例
----導(dǎo)出單個表
exec file2table 'zj','','','xzkh_sa..地區(qū)資料','c:/zj.txt',1
----導(dǎo)出整個數(shù)據(jù)庫
exec file2table 'zj','','','xzkh_sa','C:/docman',1
--導(dǎo)入調(diào)用示例
----導(dǎo)入單個表
exec file2table 'zj','','','xzkh_sa..地區(qū)資料','c:/zj.txt',0
----導(dǎo)入整個數(shù)據(jù)庫
exec file2table 'zj','','','xzkh_sa','C:/docman',0
*/
if exists(select 1 from sysobjects where name='File2Table' and objectproperty(id,'IsProcedure')=1)
drop procedure File2Table
go
create procedure File2Table
@servername varchar(200)--服務(wù)器名
,@username varchar(200)--用戶名,如果用NT驗(yàn)證方式,則為空''
,@password varchar(200)--密碼
,@tbname varchar(500)--數(shù)據(jù)庫.dbo.表名,如果不指定:.dbo.表名,則導(dǎo)出數(shù)據(jù)庫的所有用戶表
,@filename varchar(1000)--導(dǎo)入/導(dǎo)出路徑/文件名,如果@tbname參數(shù)指明是導(dǎo)出整個數(shù)據(jù)庫,則這個參數(shù)是文件存放路徑,文件名自動用表名.txt
,@isout bit--1為導(dǎo)出,0為導(dǎo)入
as
declare @sql varchar(8000)
if @tbname like '%.%.%' --如果指定了表名,則直接導(dǎo)出單個表
begin
set @sql='bcp '+@tbname
+case when @isout=1 then ' out ' else ' in ' end
+' "'+@filename+'" /w'
+' /S '+@servername
+case when isnull(@username,'')='' then '' else ' /U '+@username end
+' /P '+isnull(@password,'')
exec master..xp_cmdshell @sql
end
else
begin--導(dǎo)出整個數(shù)據(jù)庫,定義游標(biāo),取出所有的用戶表
declare @m_tbname varchar(250)
if right(@filename,1)<>'/' set @filename=@filename+'/'
set @m_tbname='declare #tb cursor for select name from '+@tbname+'..sysobjects where xtype=''U'''
exec(@m_tbname)
open #tb
fetch next from #tb into @m_tbname
while @@fetch_status=0
begin
set @sql='bcp '+@tbname+'..'+@m_tbname
+case when @isout=1 then ' out ' else ' in ' end
+' "'+@filename+@m_tbname+'.txt " /w'
+' /S '+@servername
+case when isnull(@username,'')='' then '' else ' /U '+@username end
+' /P '+isnull(@password,'')
exec master..xp_cmdshell @sql
fetch next from #tb into @m_tbname
end
close #tb
deallocate #tb
end
goTop
53 樓taito(史克威爾)回復(fù)于 2005-12-23 11:52:04 得分 2
精簡checkbox全選代碼
-----------------------------------
function CheckAll(form)
{
for (var i=0;i
{
var e = form.elements[i];
if (e.Name != "chkAll"&&e.disabled==false)
e.checked = form.chkAll.checked;
}
}
全部選中
Top54 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 11:54:52 得分 0
ADO連接數(shù)據(jù)庫字符串大全
This page contains sample ADO connection strings for ODBC DSN / DSN-Less,
OLE DB Providers, Remote Data Services (RDS), MS Remote, MS DataShape.
Also included are ADO.NET connection strings for each .NET Managed Provider
(SQLClient, OLEDB, and ODBC).
These sample connection strings are compiled
by Carl Prothman, a Microsoft Visual Basic MVP
Enjoy!
Table of Contents
ODBC DSN Connections DSN
File DSN
ODBC DSN-Less Connections ODBC Driver for AS/400
ODBC Driver for Access
ODBC Driver for dBASE
ODBC Driver for Excel
ODBC Driver for MySQL
ODBC Driver for Oracle
ODBC Driver for Paradox
ODBC Driver for SQL Server
ODBC Driver for Sybase
ODBC Driver for Sybase SQL Anywhere
ODBC Driver for Text
ODBC Driver for Teradata
ODBC Driver for Visual FoxPro
OLE DB Data Link Connections Data Link File (UDL)
OLE DB Data Provider Connections OLE DB Provider for AS/400
OLE DB Provider for Active Directory Service
OLE DB Provider for DB2
OLD DB Provider for Internet Publishing
OLE DB Provider for Index Server
OLE DB Provider for Microsoft Jet
OLE DB Provider for ODBC Databases
OLE DB Provider for Oracle (From Microsoft)
OLE DB Provider for Oracle (From Oracle)
OLE DB Provider for Simple Provider
OLE DB Provider for SQL Server
Remote Data Service (RDS) Connections RDS Data Control - Connect Property
RDS Data Control - URL Property
ADO URL Connections ADO Recordset
MS Remote Provider Connections MS Remote - Access (Jet)
MS Remote - SQL Server
Data Shape Provider Connections MS DataShape - SQL Server
.NET Managed Provider Connections SQL Client .NET Managed Provider (System.Data.SqlClient)
OLE DB .NET Managed Provider (System.Data.OleDb)
ODBC .NET Managed Provider (System.Data.ODBC)
ODBC DSN Connections
Using an ODBC DSN (Data Source Name) is a two step process.
1) You must first create the DSN via the "ODBC Data Source Administrator" program
found in your computer's Control Panel (or Administrative Tools menu in Windows 2000).
Make sure to create a SYSTEM DSN (not a USER DSN) when using ASP.
Note: You can also create the DSN via VB code.
2) Then use the following connection string - with your own DSN name of course. ;-)
ODBC - DSN
oConn.Open "DSN=AdvWorks;" & _
"Uid=Admin;" & _
"Pwd=;
You can also create and use a File DSN. Then use the following ADO Connection string:
ODBC - File DSN
oConn.Open "FILEDSN=c:/somepath/mydb.dsn;" & _
"Uid=Admin;" & _
"Pwd=;"
For more information, see: About ODBC data sources and
How to Use File DSNs and DSN-less Connections
Note: The problem with DSN is that Users can (and will) modify them (or delete by mistake),
then your program won't work so well... So it's better to use a DSN-Less or OLE DB Provider
connection string with a Trusted Connection if possible!
ODBC DSN-Less Connections
ODBC Driver for AS/400
oConn.Open "Driver={Client Access ODBC Driver (32-bit)};" & _
"System=myAS400;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
For more information, see: A Fast Path to AS/400 Client/Server
ODBC Driver for Access
For Standard Security:
oConn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=c:/somepath/mydb.mdb;" & _
"Uid=Admin;" & _
"Pwd=;"
If you are using a Workgroup (System database):
oConn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=c:/somepath/mydb.mdb;" & _
"SystemDB=c:/somepath/mydb.mdw;", _
"admin", ""
If MDB is located on a network share:
oConn.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=//myServer/myShare/myPath/myDb.mdb;"
For more information, see: Microsoft Access Driver Programming Considerations
ODBC Driver for dBASE
oConn.Open "Driver={Microsoft dBASE Driver (*.dbf)};" & _
"DriverID=277;" & _
"Dbq=c:/somepath;"
Note: Specify the filename in the SQL statement. For example:
oRs.Open "Select * From user.dbf", oConn, , ,adCmdText
Note: MDAC 2.1 (or greater) requires the Borland Database Engine (BDE) to update dBase DBF files. (Q238431).
For more information, see: dBASE Driver Programming Considerations
ODBC Driver for Excel
oConn.Open "Driver={Microsoft Excel Driver (*.xls)};" & _
"DriverId=790;" & _
"Dbq=c:/somepath/mySpreadsheet.xls;" & _
"DefaultDir=c:/somepath;"
For more information, see: Microsoft Excel Driver Programming Considerations
ODBC Driver for MySQL (via MyODBC)
To connect to a local database
oConn.Open "Driver={mySQL};" & _
"Server=MyServerName;" & _
"Option=16834;" & _
"Database=mydb;"
To connect to a remote database
oConn.Open "Driver={mySQL};" & _
"Server=db1.database.com;" & _
"Port=3306;" & _
"Option=131072;" & _
"Stmt=;" & _
"Database=mydb;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
For more information, see: Programs Known to Work with MyODBC
Top
55 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 11:55:42 得分 0
ODBC Driver for Oracle
For the current Oracle ODBC Driver from Microsoft:
oConn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=OracleServer.world;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
For the older Oracle ODBC Driver from Microsoft:
oConn.Open "Driver={Microsoft ODBC Driver for Oracle};" & _
"ConnectString=OracleServer.world;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
For more information, see: Connection String Format and Attributes
ODBC Driver for Paradox
oConn.Open "Driver={Microsoft Paradox Driver (*.db)};" & _
"DriverID=538;" & _
"Fil=Paradox 5.X;" & _
"DefaultDir=c:/dbpath/;" & _
"Dbq=c:/dbpath/;" & _
"CollatingSequence=ASCII;"
Note: MDAC 2.1 (or greater) requires the Borland Database Engine (BDE) to update Paradox ISAM fDBF files. (Q230126).
For more information, see: Paradox Driver Programming Considerations
ODBC Driver for SQL Server
For Standard Security:
oConn.Open "Driver={SQL Server};" & _
"Server=MyServerName;" & _
"Database=myDatabaseName;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
For Trusted Connection security:
oConn.Open "Driver={SQL Server};" & _
"Server=MyServerName;" & _
"Database=myDatabaseName;" & _
"Uid=;" & _
"Pwd=;"
' or
oConn.Open "Driver={SQL Server};" & _
"Server=MyServerName;" & _
"Database=myDatabaseName;" & _
"Trusted_Connection=yes;"
To Prompt user for username and password
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Driver={SQL Server};" & _
"Server=MyServerName;" & _
"DataBase=myDatabaseName;"
For more information, see: SQLDriverConnect (ODBC)
ODBC Driver for Sybase
If using the Sybase System 11 ODBC Driver:
oConn.Open "Driver={SYBASE SYSTEM 11};" & _
"Srvr=myServerName;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
If using the Intersolv 3.10 Sybase ODBC Driver:
oConn.Open "Driver={INTERSOLV 3.10 32-BIT Sybase};" & _
"Srvr=myServerName;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
For more information, see: Sybase System 10 ODBC Driver Reference Guide
ODBC Driver for Sybase SQL Anywhere
oConn.Open "ODBC; Driver=Sybase SQL Anywhere 5.0;" & _
"DefaultDir=c:/dbpath/;" & _
"Dbf=c:/sqlany50/mydb.db;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
"Dsn="""";"
Note: Including the DSN tag with a null string is absolutely critical or else you get the dreaded -7778 error.
For more information, see: Sybase SQL Anywhere User Guide
ODBC Driver for Teradata
oConn.Open "Provider=Teradata;" & _
"DBCName=MyDbcName;" & _
"Database=MyDatabaseName;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
For more information, see Teradata ODBC Driver
ODBC Driver for Text
oConn.Open "Driver={Microsoft Text Driver (*.txt; *.csv)};" & _
"Dbq=c:/somepath/;" & _
"Extensions=asc,csv,tab,txt;" & _
"Persist Security Info=False"
Note: Specify the filename in the SQL statement. For example:
oRs.Open "Select * From customer.csv", _
oConn, adOpenStatic, adLockReadOnly, adCmdText
For more information, see: Text File Driver Programming Considerations
Top
56 樓taito(史克威爾)回復(fù)于 2005-12-23 11:56:00 得分 0
'=================================================
'函數(shù)名:JoinChar
'作 用:自動判斷鏈接地址并向地址中加入 ? 或 &
'參 數(shù):strUrl ----網(wǎng)址
'返回值:加了 ? 或 & 的網(wǎng)址
'=================================================
function JoinChar(strUrl)
if strUrl="" then
JoinChar=""
exit function
end if
if InStr(strUrl,"?")
if InStr(strUrl,"?")>1 then
if InStr(strUrl,"&")
JoinChar=strUrl & "&"
else
JoinChar=strUrl
end if
else
JoinChar=strUrl & "?"
end if
else
JoinChar=strUrl
end if
end functionTop
57 樓bbsad(web程式員)回復(fù)于 2005-12-23 11:59:45 得分 2
經(jīng)典呀.非常感謝.
統(tǒng)計(jì)系統(tǒng)方面的.希望精英們能看到..
如何判斷我的廣告被點(diǎn)擊..
可能我的廣告是圖片是文件..或是其它的.
如果對我的客戶端url進(jìn)行隨機(jī)顯示.
Top
58 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 12:06:50 得分 0
ODBC Driver for Visual FoxPro
With a database container:
oConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
"SourceType=DBC;" & _
"SourceDB=c:/somepath/mySourceDb.dbc;" & _
"Exclusive=No;"
Without a database container (Free Table Directory):
oConn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
"SourceType=DBF;" & _
"SourceDB=c:/somepath/mySourceDbFolder;" & _
"Exclusive=No;"
For more information, see: Visual FoxPro ODBC Driver and Q165492
OLE DB Data Link Connections
Data Link File (UDL)
For Absolute Path:
oConn.Open "File Name=c:/somepath/myDatabaseName.udl;"
For Relative Path:
oConn.Open "File Name=myDatabaseName.udl;"
For more information, see: HOWTO: Use Data Link Files with ADO
Note: Windows 2000 no longer contains the "New | Microsoft Data Link" menu
anymore. You can add the Data Link menu back in the menu list by running the
"C:/Program Files/Common Files/System/Ole DB/newudl.reg" reg file,
then right-click on the desktop and select "New | Microsoft Data Link" menu.
Or you can also create a Data Link file by creating a text file and change it's
file extension to ".udl", then double-click the file.
OLE DB Provider Connections
OLE DB Provider for AS/400
oConn.Open "Provider=IBMDA400;" & _
"Data source=myAS400;"
"User Id=myUsername;" & _
"Password=myPassword;"
For more information, see: A Fast Path to AS/400 Client/Server
OLE DB Provider for Active Directory Service
oConn.Open "Provider=ADSDSOObject;" & _
"User Id=myUsername;" & _
"Password=myPassword;"
For more information, see: Microsoft OLE DB Provider for Microsoft Active Directory Service
OLE DB Provider for DB2
oConn.Open = "Provider=DB2OLEDB;" &
"Network Transport Library=TCPIP;" &
"Network Address=MyServer;" & _
"Package Collection=MyPackage;" &
"Host CCSID=1142"
"Initial Catalog=MyDB;" &
"User ID=MyUsername;" & _
"Password=MyPassword;"
For more information, see: OLE DB Provider for DB2
and INF: Configuring Data Sources for the Microsoft OLE DB Provider for DB2
OLE DB Provider for Index Server
oConn.Open "Provider=msidxs;" & _
"Data source=MyCatalog;"
For more information, see: Microsoft OLE DB Provider for Microsoft Indexing Service
OLE DB Provider for Internet Publishing
oConn.Open "Provider=MSDAIPP.DSO;" & _
"Data Source=http://mywebsite/myDir;" & _
"User Id=myUsername;" & _
"Password=myPassword;"
For more information, see: Microsoft OLE DB Provider for Internet Publishing and Q245359
OLE DB Provider for Microsoft Jet
For standard security:
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:/somepath/myDb.mdb;" & _
"User Id=admin;" & _
"Password=;"
If using a Workgroup (System Database):
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:/somepath/mydb.mdb;" & _
"Jet OLEDB:System Database=MySystem.mdw;", _
"admin", ""
Note, remember to convert both the MDB and the MDW to the 4.0 database format when using the 4.0 OLE DB Provider.
If MDB has a database password:
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:/somepath/mydb.mdb;" & _
"Jet OLEDB:Database Password=MyDbPassword;", _
"admin", ""
If MDB is located on a network share:
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=//myServer/myShare/myPath/myDb.mdb;
If want to open up the Access database exclusively:
oConn.Mode = adModeShareExclusive
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:/somepath/myDb.mdb;" & _
"User Id=admin;" & _
"Password=;"
For more information, see: OLE DB Provider for Microsoft Jet, Q191754, Q225048, Q239114, and Q271908
You can also open an Excel Spreadsheet using the "OLE DB Provider for Microsoft Jet"
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:/somepath/myExcelSpreadsheet.xls;" & _
"Extended Properties=""Excel 8.0;HDR=Yes;"";"
Where "HDR=Yes" means that there is a header row in the cell range
(or named range), so the provider will not include the first row of the
selection into the recordset. If "HDR=No", then the provider will include
the first row of the cell range (or named ranged) into the recordset.
For more information, see: Q278973
You can also open a Text File using the "OLE DB Provider for Microsoft Jet"
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:/somepath/;" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited;"";"
' Then open a recordset based on a select on the actual file
oRs.Open "Select * From MyTextFile.txt", oConn, adOpenStatic, adLockReadOnly, adCmdText
For more information, see: Q262537
OLE DB Provider for ODBC Databases
For Access (Jet):
oConn.Open "Provider=MSDASQL;" & _
"Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=c:/somepath/mydb.mdb;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
請不要加我qq
有問題這里發(fā)貼就可以了。
再苦再累也要堅(jiān)強(qiáng)
學(xué)會忍耐
學(xué)會憂愁
學(xué)會放棄
學(xué)會方向
失敗重來成功再來
今年家鄉(xiāng)有人拿奧運(yùn)金牌!光榮啊!
2003-3-7 10:32
Roman
榮譽(yù)版主
Mad zI
積分 789
發(fā)帖 759
注冊 2003-2-13
來自 江西.豐城
狀態(tài) 離線 2樓
For SQL Server:
oConn.Open "Provider=MSDASQL;" & _
"Driver={SQL Server};" & _
"Server=myServerName;" & _
"Database=myDatabaseName;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
For more information, see: Microsoft OLE DB Provider for ODBC
OLE DB Provider for Oracle (from Microsoft)
oConn.Open "Provider=msdaora;" & _
"Data Source=MyOracleDB;" & _
"User Id=myUsername;" & _
"Password=myPassword;"
For more information, see: Microsoft OLE DB Provider for Oracle
OLE DB Provider for Oracle (from Oracle)
For Standard Security:
oConn.Open "Provider=OraOLEDB.Oracle;" & _
"Data Source=MyOracleDB;" & _
"User Id=myUsername;" & _
"Password=myPassword;"
For a Trusted Connection:
oConn.Open "Provider=OraOLEDB.Oracle;" & _
"Data Source=MyOracleDB;" & _
"User Id=/;" & _
"Password=;"
' Or
oConn.Open "Provider=OraOLEDB.Oracle;" & _
"Data Source=MyOracleDB;" & _
"OSAuthent=1;"
Note: "Data Source=" must be set to the appropriate Net8 name which is known to the naming method in use. For example, for Local Naming, it is the alias in the tnsnames.ora file; for Oracle Names, it is the Net8 Service Name.
For more information, see: Connecting to an Oracle Database
(Note, if you get a Logon dialog, then click Cancel, then perform a one-time free signup with Oracle's TechNet system)Top
59 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 12:07:34 得分 0
OLE DB Provider for Simple Provider
The Microsoft OLE DB Simple Provider (OSP) allows ADO to access any data for which a provider has
been written using the OLE DB Simple Provider Toolkit. Simple providers are intended to access data
sources that require only fundamental OLE DB support, such as in-memory arrays or XML documents.
OSP in MDAC 2.6 has been enhanced to support opening hierarchical ADO Recordsets over arbitrary
XML files. These XML files may contain the ADO XML persistence schema, but it is not required. This
has been implemented by connecting the OSP to the MSXML2.DLL, therefore MSXML2.DLL or newer is
required.
oConn.Open "Provider=MSDAOSP;" & _
"Data Source=MSXML2.DSOControl.2.6;"
oRS.Open "http://WebServer/VirtualRoot/MyXMLFile.xml", oConn
For more information, see: Microsoft OLE DB Simple Provider
OLE DB Provider for SQL Server
For Standard Security:
oConn.Open "Provider=sqloledb;" & _
"Data Source=myServerName;" & _
"Initial Catalog=myDatabaseName;" & _
"User Id=myUsername;" & _
"Password=myPassword;"
For a Trusted Connection:
oConn.Open "Provider=sqloledb;" & _
"Data Source=myServerName;" & _
"Initial Catalog=myDatabaseName;" & _
"Integrated Security=SSPI;"
To connect to a "Named Instance" (SQL Server 2000)
oConn.Open "Provider=sqloledb;" & _
"Data Source=myServerName/Inst2;" & _
"Initial Catalog=myDatabaseName;" & _
"User Id=myUsername;" & _
"Password=myPassword;"
To Prompt user for username and password:
oConn.Provider = "sqloledb"
oConn.Properties("Prompt") = adPromptAlways
oConn.Open "Data Source=myServerName;" & _
"Initial Catalog=myDatabaseName;"
To connect via an IP address:
oConn.Open "Provider=sqloledb;" & _
"Data Source=xxx.xxx.xxx.xxx,1433;" & _
"Network Library=DBMSSOCN;" & _
"Initial Catalog=myDatabaseName;" & _
"User ID=myUsername;" & _
"Password=myPassword;"
Note:
- xxx.xxx.xxx.xxx is an IP address
- "Network Library=DBMSSOCN" tells OLE DB to use TCP/IP rather than Named Pipes (Q238949)
- 1433 is the default port number for SQL Server
- You can also add "Encrypt=yes" for encryption
For more information, see: Microsoft OLE DB Provider for SQL Server
Remote Data Service (RDS) Connections
The following examples show how to connect to a remote database using the RDS Data Control.
When using the RDS DataControl's Server/SQL/Connect properties, the RDS DataControl uses the
RDS DataFactory on the remote server. If you use the RDS DataControl's URL property,
then the RDS DataFactory is not used at all.
WARNING: The RDS DataFactory can be a major security hole if not setup and configured correctly!
For more information, see RDS FAQ #24
RDS DataControl - Connect Property
With the RDS default handler disabled (not recommend due to security risks):
With oRdc
.Server = "http://carl2"
.Sql = "Select * From Authors Where State = 'CA'"
.Connect = "Provider=sqloledb;" & _
"Data Source=(local);" & _
"Initial Catalog=pubs;" & _
"User Id=sa;" & _
"Password=;"
.Refresh
End With
With the RDS default handler enabled (recommend):
With oRdc
.Server = "http://carl2"
.Handler = "MSDFMAP.Handler"
.Connect = "Data Source=MyConnectTag;"
.Sql = "MySQLTag(""CA"")"
.Refresh
End With
The corresponding CONNECT and SQL sections in the default handler /WINNT/MSDFMAP.INI file would be:
[connect MyConnectTag]
Access = ReadWrite
Connect = "Provider=sqloledb;Data Source=(local);Initial Catalog=pubs;User Id=sa;Password=;"
[sql MySQLTag]
Sql = "Select * From Authors Where State = '?'"
For more information about the RDS Default Handler, see:
Q243245, Q230680, and RDS Customization Handler Microsoft articles
RDS DataControl - URL Property
To get records from a remote database:
With oRdc
.URL = "http://carlp0/Authors_GetByState.asp?state=CA"
.Refresh
End With
To save, set the URL property to an ASP web page:
With oRdc
.URL = "http://carlp0/rdsdatacontrol/Authors_Save.asp"
.SubmitChanges
End With
For more information, see: RDS URL Property
ADO URL Connections
ADO 2.5+ allows you to open up a Recordset based on XML returned from an ASP file over HTTP.
This feature doesn't use RDS at all.
ADO Recordset
To get records from a remote database:
oRs.Open "http://carlp0/Authors_GetByState.asp?state=CA", , _
adOpenStatic, adLockBatchOptimistic
To save changes, you must use the MSXML's XMLHTTP object to POST back the updated XML.
The Recordset's Update and UpdateBatch methods will not work in this case.
' Save Recordset into Stream
Set oStm = New ADODB.Stream
oRs.Save oStm, adPersistXML
' Use MSXML's XMLHTTP object to open ASP and post a XML stream
Set oXMLHTTP = New MSXML2.XMLHTTP30
oXMLHTTP.Open "POST", "http://carlp0/Authors_Save.asp", False
oXMLHTTP.Send oStm.ReadText
' If an error occurred
If oXMLHTTP.Status = 500 Then
Debug.Print oXMLHTTP.statusText
End If
For more information, see: ADO Recordset's Open Method
MS Remote Provider Connections
The following connections strings use Microsoft's remote provider (MS Remote). The MS Remote
provider tells ADO to communicate with the remote server (via the RDS DataFactory) and to use
the remote provider that is installed on the remote server.
WARNING: The RDS DataFactory can be a major security hole if not setup and configured correctly!
For more information, see RDS FAQ #24
MS Remote - Access (Jet)
If you want to use an ODBC DSN on the remote machine:
oConn.Open "Provider=MS Remote;" & _
"Remote Server=http://myServerName;" & _
"Remote Provider=MSDASQL;" & _
"DSN=AdvWorks;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
If you want to use an OLE DB Provider on the remote machine:
oConn.Open "Provider=MS Remote;" & _
"Remote Server=http://myServerName;" & _
"Remote Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:/somepath/mydb.mdb;", _
"admin", ""
If you want to use an OLE DB Provider on the remote machine (via RDS DataFactory Default Handler):
oConn.Open "Provider=MS Remote;" & _
"Remote Server=http://myServerName;" & _
"Handler=MSDFMAP.Handler;" & _
"Data Source=MyAdvworksConn;"
The corresponding entry in the /winnt/Msdfmap.ini file would be:
[connect MyAdvworksConn]
Access = ReadWrite
Connect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=mydb.mdb;" & _
"User Id=admin;" & _
"Password=;"
Top
60 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 12:07:57 得分 0
MS Remote - SQL Server
If you want to use an ODBC DSN on the remote machine:
oConn.Open "Provider=MS Remote;" & _
"Remote Server=http://myServerName;" & _
"Remote Provider=MSDASQL;" & _
"DSN=myDatabaseName;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
If you want to use an OLE DB Provider on the remote machine:
oConn.Open "Provider=MS Remote;" & _
"Remote Server=http://myServerName;" & _
"Remote Provider=SQLOLEDB;" & _
"Data Source=myServerName;" & _
"Initial Catalog=myDatabaseName;" & _
"User ID=myUsername;" & _
"Password=myPassword;"
If you want to use an OLE DB Provider on the remote machine (via RDS DataFactory Default Handler):
oConn.Open "Provider=MS Remote;" & _
"Remote Server=http://myServerName;" & _
"Handler=MSDFMAP.Handler;" & _
"Data Source=MyPubsConn;"
The corresponding entry in the /winnt/Msdfmap.ini file would be:
[connect MyPubsConn]
Access = ReadWrite
Connect = "Provider=SQLOLEDB;" & _
"Data Source=myServerName;" & _
"Initial Catalog=myDatabaseName;" & _
"User ID=myUsername;" & _
"Password=myPassword;"
For more information, see: Microsoft OLE DB Remoting Provider and Q240838
Data Shape Provider Connections
MS DataShape - SQL Server
oConn.Open "Provider=MSDataShape;" & _
"Data Provider=SQLOLEDB;" & _
"Data Source=mySQLServerName;" & _
"Initial Catalog=myDatabase;" & _
"User ID=myUsername;" & _
"Password=myPassword;"
Then use a Shape command with SQL strings:
sSQL = "SHAPE {select * from authors} " & _
"APPEND ({select * from titleauthor} AS chapter " & _
"RELATE au_id TO au_id)"
Or use a Shape command that calls Stored Procedures:
sSQL = "SHAPE {exec spAuthors_LoadAll} " & _
"APPEND ({exec spTitleAuthor_LoadAll} AS chapter " & _
"RELATE au_id TO au_id)"
For more information, see: Microsoft Data Shaping Service for OLE DB and Q288409
.NET Managed Provider Connections
SQL Client .NET Managed Provider (System.Data.SqlClient)
The SQL Client .NET Managed Provide allows you to connect to a Microsoft SQL Server 7.0
or 2000 database. For Microsoft SQL Server 6.0 or earlier, use the OLE DB .NET Data Provider
with the "SQL Server OLE DB Provider" (SQLOLEDB).
Dim oSQLConnection As SqlClient.SqlConnection
Dim sConnString As String
sConnString = "Data Source=(local);" & _
"Initial Catalog=NorthWind;" & _
"Integrated Security=SSPI;" & _
"Pooling=True;" & _
"Min Pool Size=10;" & _
"Max Pool Size=50;" & _
"Connection Lifetime=30;" & _
"Connection Reset=True;" & _
"Enlist=True;"
oSQLConnection = New SqlClient.SqlConnection(sConnString)
oSQLConnection.Open()
For more information, see: System.Data.SQL Namespace and .NET Data Providers
Note: 'SQL' namespace got renamed to 'SQLClient'
OLE DB .NET Managed Provider (System.Data.OleDb)
The OLE DB .NET Data Provider uses native OLE DB through COM interop to enable data access.
To use the OLE DB .NET Data Provider, you must also use an OLE DB provider (e.g. SQLOLEDB,
MSDAORA, or Microsoft.JET.OLEDB.4.0).
For SQL Server OLE DB Provider (for SQL Server 6.0 or earlier)
Dim oOleDbConnection As OleDb.OleDbConnection
Dim sConnString As String
sConnString = "Provider=sqloledb;" & _
"Data Source=myServerName;" & _
"Initial Catalog=myDatabaseName;" & _
"User Id=myUsername;" & _
"Password=myPassword;"
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
For JET OLE DB Provider:
Dim oOleDbConnection As OleDb.OleDbConnection
Dim sConnString As String
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:/Work/nwind.mdb;" & _
"User ID=Admin;" & _
"Password="";"
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
For more information, see: System.Data.OleDb Namespace and .NET Data Providers
Note: 'ADO' namespace got renamed to 'OleDb'
ODBC .NET Managed Provider (System.Data.ODBC)
The ODBC .NET Data Provider is an add-on component to the .NET Framework SDK Beta 2.
It provides access to native ODBC drivers the same way the OLE DB .NET Data Provider
provides access to native OLE DB providers.
For SQL Server ODBC Driver:
Dim oODBCConnection As Odbc.OdbcConnection
Dim sConnString As String
' Create and open a new ODBC Connection
sConnString = "Driver={SQL Server};" & _
"Server=MySQLServerName;" & _
"Database=MyDatabaseName;" & _
"Uid=MyUsername;" & _
"Pwd=MyPassword;"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()
For Oracle ODBC Driver:
Dim oODBCConnection As Odbc.OdbcConnection
Dim sConnString As String
' Create and open a new ODBC Connection
sConnString = "Driver={Microsoft ODBC for Oracle};" & _
"Server=OracleServer.world;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()
For Access (JET) ODBC Driver:
Dim oODBCConnection As Odbc.OdbcConnection
Dim sConnString As String
' Create and open a new ODBC Connection
sConnString = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=c:/somepath/mydb.mdb;" & _
"Uid=Admin;" & _
"Pwd=;"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()
For all other ODBC Drivers:
Dim oODBCConnection As Odbc.OdbcConnection
Dim sConnString As String
' Create and open a new ODBC Connection
sConnString = "Dsn=myDsn;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"
oODBCConnection = New Odbc.OdbcConnection(sConnString)
oODBCConnection.Open()
Top
61 樓yjbnew(偉大的光榮的正確的ASP千歲千歲千千歲)回復(fù)于 2005-12-23 12:11:11 得分 2
mark
Top
62 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 12:11:32 得分 0
xmlhttp使用范例(帶注釋):
On Error Resume Next
Server.ScriptTimeOut=9999999
Function getHTTPPage(Path)
t = GetBody(Path)
getHTTPPage=BytesToBstr(t,"GB2312")
End function
'首先,進(jìn)行小偷程序的一些初始化設(shè)置,以上代碼的作用分別是忽略掉所有非致命性錯誤,把小偷程序的運(yùn)行'超時時間設(shè)置得很長(這樣不會出現(xiàn)運(yùn)行超時的錯誤),轉(zhuǎn)換原來默認(rèn)的UTF-8編碼轉(zhuǎn)換成GB2312編碼,否則'直接用XMLHTTP組件調(diào)用有中文字符的網(wǎng)頁得到的將是亂碼。
Function GetBody(url)
on error resume next
Set Retrieval = CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", url, False, "", ""
.Send
GetBody = .ResponseBody
End With
Set Retrieval = Nothing
End Function
'然后調(diào)用XMLHTTP組件創(chuàng)建一個對象并進(jìn)行初始化設(shè)置。
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
Function Newstring(wstr,strng)
Newstring=Instr(lcase(wstr),lcase(strng))
if Newstring<=0 then Newstring=Len(wstr)
End Function
'處理抓取回來的數(shù)據(jù)需要調(diào)用adodb.stream組件并進(jìn)行初始化設(shè)置。
%>
'以下即為頁面顯示部分
Dim wstr,str,url,start,over,city
'定義一些需要使用到的變量
city = Request.QueryString("id")
'程序傳回的ID變量(即用戶選擇的城市)賦給id
url="http://www.pifoo.com"
'這里設(shè)置需要抓取的頁面地址,當(dāng)然你也可以直接指定某個地址而不使用變量
wstr=getHTTPPage(url)
'獲取指定頁面的全部數(shù)據(jù)
start=Newstring(wstr," ")
'這里設(shè)置需要處理的數(shù)據(jù)的頭部,這個變量應(yīng)視不同情況而設(shè)置,具體內(nèi)容可以通過查看需要抓取的頁面的源'代碼來確定。因?yàn)樵谶@個程序里我們需要抓取整個頁面,所以設(shè)置為頁面全部抓取。注意,設(shè)置的內(nèi)容必須是''頁面內(nèi)容唯一的,不可以重復(fù)。
over=Newstring(wstr," ")
'和start相對應(yīng)的就是需要處理的數(shù)據(jù)的尾部,同樣的,設(shè)置的內(nèi)容必須是頁面中唯一的。
body=mid(wstr,start,over-start)
'設(shè)置顯示頁面的范圍
'下面通過replace可以用一些字符替換掉數(shù)據(jù)中指定的字符。
'body = replace(body,"http://www.pifoo.com","aaa")
'本程序中已經(jīng)完成了替換的工作,如果有其他需要的話可以繼續(xù)進(jìn)行類似的替換操作。
response.write body
%>Top
63 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 12:17:20 得分 0
笨狼XSLT練習(xí)器body
{
font-size:12;
BACKGROUND: #DADADA;
margin-left:20;
}
#blockXML
{
font-family:Verdana;
font-size:12px;
overflow:scroll;
height:400;
top:40;
left:20;
}
input
{
width:350;
}
#blockXSL
{
POSITION: absolute;
font-family:Verdana;
font-size:12px;
overflow:scroll;
height:400;
top:40;
}
#showMe
{
font-family:Verdana;
font-size:12px;
height:100;
overflow:visible;
top:300;
left:20;
}
?XML?
?XSL??
開始轉(zhuǎn)換
預(yù)覽結(jié)果
window.resizeTo(window.screen.availWidth,window.screen.availHeight);
window.moveTo(0,0);
blockXML.style.width = parseInt(window.screen.availWidth * 0.46);
blockXSL.style.width = blockXML.style.width ;
blockXSL.style.left = parseInt(window.screen.availWidth * 0.46) + 30;
showMe.style.width = parseInt(window.screen.availWidth * 0.92)+ 10;
var fso
fso = new ActiveXObject("Scripting.FileSystemObject");
var xmldoc, xsldoc;
xmldoc = new ActiveXObject("MSXML2.DOMDocument");
xsldoc = new ActiveXObject("MSXML2.DOMDocument");
xmldoc.async = false;
xsldoc.async = false;
function browse()
{
var win=window.open();
win.document.write(showMe.value);
}
function showXML()
{//在文本框內(nèi)加載XML
if(Validator(fileXML.value,"XML"))
{
if(fso.FileExists(fileXML.value))
{
var f = fso.GetFile(fileXML.value);
var ts = f.OpenAsTextStream(1, -2);
var s="";
if(!ts.AtEndOfStream)
{
s = ts.ReadAll();
}
ts.Close();
blockXML.value = s;
fileXML.value ="";
}
}
else
{
alert("XML格式錯誤!");
}
}
function showXSL()
{//在文本框內(nèi)加載XSL
if(Validator(fileXSL.value,"XSL") || Validator(fileXSL.value,"XSLT"))
{
if(fso.FileExists(fileXSL.value))
{
var f = fso.GetFile(fileXSL.value);
var ts = f.OpenAsTextStream(1, -2);
var s="";
if(!ts.AtEndOfStream)
{
s = ts.ReadAll();
}
ts.Close();
blockXSL.value = s;
fileXSL.value ="";
}
}
else
{
alert("XSL/XSLT格式錯誤!");
}
}
function Validator(inStr,outStr)
{//檢查文件格式
var last=inStr.match(/^(.*)(/.)(.{1,8})$/)[3];
last=last.toUpperCase();
if(last==outStr)
{
return true;
}
else
{
return false;
}
}
function parseXML()
{//解析
if(!blockXML.value ||!blockXSL.value)
{
return
}
if(!xmldoc.loadXML(blockXML.value))
{
alert("XML未加載成功!")
}
if(!xsldoc.loadXML(blockXSL.value))
{
alert("XSL未加載成功!")
}
var s = xmldoc.transformNode(xsldoc);
showMe.value = s;
}
Top
64 樓likun_vc(www.netin4.com)回復(fù)于 2005-12-23 12:29:15 得分 2
超經(jīng)典的也是最簡單的:它就是 rs.close conn.close (結(jié)束一切)Top
65 樓MaxIE(MaxIE)回復(fù)于 2005-12-23 12:33:26 得分 2
關(guān)注................Top
66 樓znjgress(四空和尚)回復(fù)于 2005-12-23 12:52:15 得分 2
笨狗 和 笨狼
應(yīng)該原來是一家的Top
67 樓phuson(寂寞沙洲)回復(fù)于 2005-12-23 13:43:02 得分 2
68 樓yfcheng(亦風(fēng)--斷線D風(fēng)箏)回復(fù)于 2005-12-23 13:46:00 得分 2
'向購物車中添加某一物品
sub puttoshopcart(goodsid,session("shopcart"))
if len(session("shopcart"))=0 then
session("shopcart")=goodsid
elseif instr(goodsid,session("shopcart"))<0 then
session("shopcart")=session("shopcart") &","&goodsid
response.Write("
location.href ='shopcartlist.asp';
window.opener=null;
window.close();
")
else
response.Write("
alert('此物品你已選購,如需增加訂購,請直接更改訂購數(shù)量');
location.href ='shopcartlist.asp';
window.opener=null;
window.close();
")
end if
end sub
'刪除購物車中的某一物品
sub delfromshopcart(goodsid,session("shopcart"))
if len(session("shopcart"))<>0 then
session("shopcart")="" '清空原session("shopcart")值
goods=split(session("shopcart"),",")
for i=0 to ubound(goods)
if session("shopcart")=""then
session("shopcart")=goods(i)
else
if goods(i)=goodsid then next
session("shopcart")=session("shopcart")&","&goods(i) '賦新值到session("shopcart")
end if
next
end sub
%>
Top
69 樓yousite1(國霧)回復(fù)于 2005-12-23 13:56:51 得分 2
路過,資料好多。看暈了。。。。
Top
70 樓luluxiang(格格周)回復(fù)于 2005-12-23 14:36:46 得分 0
上面的問題有人幫忙解決沒阿?
http://product.zol.com.cn/diy/這種攢機(jī)的東西是怎么做的阿?
Top
71 樓ReViSion(和尚)回復(fù)于 2005-12-23 14:44:41 得分 2
哈哈,學(xué)習(xí)Top
72 樓hssfox()回復(fù)于 2005-12-23 14:46:48 得分 2
73 樓tjj36(憂郁的眼睛)回復(fù)于 2005-12-23 14:57:28 得分 2
74 樓wxf0104(西方失敗007)回復(fù)于 2005-12-23 15:04:49 得分 2
好多呀,收藏。Top
75 樓cds27(http://blog.csdn.net/cds27/)回復(fù)于 2005-12-23 15:07:45 得分 2
接分接分,怎么還沒看到斑竹那邊的名字刷新啊Top
76 樓eastjazz(德仔&我是小仔仔 www.dezai.cn)回復(fù)于 2005-12-23 15:11:33 得分 2
有沒有新一點(diǎn)的,這些都傳了好多資了的.Top
77 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 15:51:30 得分 0
呵呵,下面這段代碼純屬娛樂(注:先開起QQ,最小化QQ后,再在iis里運(yùn)行下面這段代碼,發(fā)現(xiàn)什么沒?)
try
{
var xmlhttp=new ActiveXObject("TimwpDll.TimwpCheck");
location.href='Tencent://Message/?Menu=no&Uin=10000';
}
catch(e)
{}
Top
78 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 15:56:46 得分 0
動態(tài)設(shè)定表單域數(shù)量(如文本框是1個還是4個):
| 文件上傳 |
| 需要上傳的個數(shù): |
function exec()
{
waitting.style.visibility="visible";
upload.style.visibility="hidden";
}
function setid()
{
if(window.form1.upcount.value>0)
{
str='';
for(i=1;i<=window.form1.upcount.value;i++)
str+='文件'+i+':
';
window.upid.innerHTML=str+'';
}
}
setid();
Top
79 樓abillchen(依然)回復(fù)于 2005-12-23 16:13:16 得分 2
'----------分頁條---------------
'Totals: 總記錄數(shù)
'Pages: 總頁數(shù)
'PageNo: 當(dāng)前頁碼
'FileName: 分頁文件名
'作者: Abill.chen
'時間: 2004 05 18
'------------------------------
function PageBar(Totals,Pages,PageNo,FileName)
if (Totals="" or Totals="0") then PageBar=""
dim ReStr,TempStr
TempStr=""
ReStr="
總計(jì)["&Totals&"]條記錄??共["&Pages&"]頁??當(dāng)前第["&PageNo&"]頁? "
ReStr=ReStr&"去第"
for i=1 to cint(Pages)
TempStr=TempStr&"
TempStr=TempStr&">"&i&"
"next
ReStr=ReStr&TempStr&"頁
"PageBar=ReStr
end function
'----------分頁條(帶查詢條件)---------------
'Totals: 總記錄數(shù)
'Pages: 總頁數(shù)
'PageNo: 當(dāng)前頁碼
'FileName: 分頁文件名
'Other: 查詢條件
'作者: Abill.chen
'時間: 2004 05 18
'------------------------------
function PageBar2(Totals,Pages,PageNo,FileName,Other)
'if (Totals="" or Totals="0") then PageBar=""
dim ReStr,TempStr
TempStr=""
ReStr="
總計(jì)["&Totals&"]條記錄??共["&Pages&"]頁??當(dāng)前第["&PageNo&"]頁? "
ReStr=ReStr&"去第"
for i=1 to cint(Pages)
TempStr=TempStr&"
TempStr=TempStr&">"&i&"
"next
ReStr=ReStr&TempStr&"頁
"PageBar2=ReStr
end functionTop
80 樓abillchen(依然)回復(fù)于 2005-12-23 16:17:43 得分 0
'-----------------按指定的sql生成下接列表--------------------
'sql:指字的SQL語.注意第一個字段為下拉列表的值,第二個字段為下接列表的顯示值.其它字段無效
'Selname:下接列表名
'DefaultValue:默讓選項(xiàng)
'作者:Abill.chen
'時間:2004 06 16
'注:本函數(shù)要用到頁面級連接對象
'---------------------------------------------------------
function GetSelect2(sql,Selname,DefaultValue)
dim RsSe,ReStr,TempStr
set RsSe=server.createobject("ADODB.recordset")
RsSe.open sql,conn,1,1
if RsSe.eof then
ReStr="無法得到下拉列表"
else
TempStr=""
ReStr="--請選擇--"
while not RsSe.eof
if(Trim(RsSe.fields(0).value)=DefaultValue)then
TempStr=TempStr&""&Trim(RsSe.fields(1).value)&""
else
TempStr=TempStr&""&Trim(RsSe.fields(1).value)&""
end if
RsSe.movenext
wend
RsSe.close
ReStr=ReStr&TempStr&""
end if
set RsSe=nothing
GetSelect2=ReStr
end function
更經(jīng)典的ASP模板技術(shù),下回貼Top
81 樓ph580(.Net,我喜歡!www.bjcan.com/hengxing)回復(fù)于 2005-12-23 16:19:20 得分 0
看后一個感覺
亂。。。一天就收了這么多貼Top
82 樓Athickhead(穿著三角褲到處跑不叫裸奔)回復(fù)于 2005-12-23 16:19:36 得分 2
頂,好東東。Top
83 樓wangyingdong(初學(xué)asp.net)回復(fù)于 2005-12-23 16:28:46 得分 2
這些都是網(wǎng)上已經(jīng)流行很多年的代碼了,樓主要創(chuàng)新,原創(chuàng)!!1
支持!!Top
84 樓rehearts(閃閃紅心)回復(fù)于 2005-12-23 16:40:48 得分 2
想起去年做一個生成excel的例子,以前別人貼過的代碼都少了tou.txt 和di.txt,現(xiàn)在居然有人能完整的貼出來,有種同志的感覺 呵呵,Top
85 樓abillchen(依然)回復(fù)于 2005-12-23 16:49:51 得分 0
建議版主整理一下啊.打包,給個下載地址啊.Top
86 樓greytrack(沙灘中的魚)回復(fù)于 2005-12-23 16:52:12 得分 2
強(qiáng)貼,這里先頂
再苦再累也要堅(jiān)強(qiáng)
學(xué)會忍耐
學(xué)會憂愁
學(xué)會放棄
學(xué)會方向
失敗重來成功再來
sqlserver海量數(shù)據(jù)分頁的存儲過程
-- 獲取指定頁的數(shù)據(jù)
CREATE PROCEDURE pagination3
@tblName varchar(255), -- 表名
@strGetFields varchar(1000) = '*', -- 需要返回的列
@fldName varchar(255)='', -- 排序的字段名
@PageSize int = 10, -- 頁尺寸
@PageIndex int = 1, -- 頁碼
@doCount bit = 0, -- 返回記錄總數(shù), 非 0 值則返回
@OrderType bit = 0, -- 設(shè)置排序類型, 非 0 值則降序
@strWhere varchar(1500) = '' -- 查詢條件 (注意: 不要加 where)
AS
declare @strSQL varchar(5000) -- 主語句
declare @strTmp varchar(110) -- 臨時變量
declare @strOrder varchar(400) -- 排序類型
if @doCount != 0
begin
if @strWhere !=''
set @strSQL = "select count(*) as Total from [" + @tblName + "] where "+@strWhere
else
set @strSQL = "select count(*) as Total from [" + @tblName + "]"
end
--以上代碼的意思是如果@doCount傳遞過來的不是0,就執(zhí)行總數(shù)統(tǒng)計(jì)。以下的所有代碼都是@doCount為0的情況
else
begin
if @OrderType != 0
begin
set @strTmp = "
set @strOrder = " order by [" + @fldName +"] desc"
--如果@OrderType不是0,就執(zhí)行降序,這句很重要!
end
else
begin
set @strTmp = ">(select max"
set @strOrder = " order by [" + @fldName +"] asc"
end
if @PageIndex = 1
begin
if @strWhere != ''
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from [" + @tblName + "] where " + @strWhere + " " + @strOrder
else
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from ["+ @tblName + "] "+ @strOrder
--如果是第一頁就執(zhí)行以上代碼,這樣會加快執(zhí)行速度
end
else
begin
--以下代碼賦予了@strSQL以真正執(zhí)行的SQL代碼
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from ["
+ @tblName + "] where [" + @fldName + "]" + @strTmp + "(["+ @fldName + "]) from (select top " + str((@PageIndex-1)*@PageSize) + " ["+ @fldName + "] from [" + @tblName + "]" + @strOrder + ") as tblTmp)"+ @strOrder
if @strWhere != ''
set @strSQL = "select top " + str(@PageSize) +" "+@strGetFields+ " from ["
+ @tblName + "] where [" + @fldName + "]" + @strTmp + "(["
+ @fldName + "]) from (select top " + str((@PageIndex-1)*@PageSize) + " ["
+ @fldName + "] from [" + @tblName + "] where " + @strWhere + " "
+ @strOrder + ") as tblTmp) and " + @strWhere + " " + @strOrder
end
end
exec (@strSQL)
GO
Top
87 樓wenbang20(葉子)回復(fù)于 2005-12-23 17:27:08 得分 2
發(fā)個Chat聊天程序:
Else
Response.clear
dim talk
If Request.Form("nick")<>"" then
Session("nick")=Request.Form("nick")
End if
%>
說話:
離開
If Request.Form("log")<>1 then
If trim(Request.Form("talk"))="" then
talk=Session("nick")&"不說一句話就想來敷衍大家"
Else
talk=trim(Request.Form("talk"))
End If
Application.lock
Application("show")="來自"&Request.ServerVariables("remote_addr")& "的" &Session("nick")&"在"&time& "的時候說:" &talk& "
" &Application("show")
Application.UnLock
Response.Write Application("show")
End if
%>
簡單解釋:
1,的作用就是判斷當(dāng)前頁面接受的方式,如果為GET方式則會顯示“要求輸入昵稱”的表單頁。因?yàn)轫撁娴哪唤邮芊绞綖镚ET,當(dāng)在URL地址欄直接敲入時,也就是沒有任何信息的時候,就應(yīng)該顯示要求“輸入昵稱”。
2,和下面的If Request.Form("log")<>1 then是有關(guān)聯(lián)的:顯然第一次輸入昵稱進(jìn)入,同樣將log隱藏域發(fā)送。但作為第一次的進(jìn)入是無任何語句發(fā)言的,所以判斷接受的log值不為1,亦即非首次登錄(表示已經(jīng)登錄)時,執(zhí)行內(nèi)部相關(guān)聊天顯示程序。
3,trim(Request.Form("talk"))="",trim就是個函數(shù)了:刪去字符串前,后的空格。初此,還有rtrim():去掉字符串后的空格;ltrim():去掉字符串前的空格。
4.Application變量的疊加功能,每次Application("show")的值都建立在原有Application變量值的基礎(chǔ)之上,再附加上最新的聊天內(nèi)容:talk變量的值。這樣就保證所有用戶都能看到的共享信息了。
Top
88 樓BlueDestiny(Design Life - never-online.net)回復(fù)于 2005-12-23 17:37:52 得分 2
first,以下均為個人意見,喜歡的就看下去,不喜歡可以不看。
類似的代碼已經(jīng)有很多人已經(jīng)發(fā)過了,而且已經(jīng)發(fā)過不只一次了,建議弄點(diǎn)新的吧。如果要的話,直接發(fā)貼說把自己收藏的貼子貼出來,這才是好的,像這種初學(xué)的東西,到處都有,google,baidu,CSDN search都有。如果要真正的讓人水平提高,要教初學(xué)者不是給code,而是給經(jīng)驗(yàn),當(dāng)遇到難題時,你如何得到解題思路,調(diào)試程序是怎么調(diào)試的,還有怎么利用msdn,goole,baidu等等資源,“高手”和“初學(xué)者”的差距就在這里,我看網(wǎng)上的網(wǎng)友問的問題,百分之七八十都可以search得到。所以,很多人也就懶得答了,有的題目都答得快爛了
兔子和笨狼已經(jīng)把一些asp相關(guān)的東西全整成FAQ了,樓主的心意還是要支持的,方法不支持。
but 我們真正所需要的,是經(jīng)驗(yàn),而非入門,right?,建議你重新開貼收集收藏貼吧(不是類似ADO數(shù)據(jù)庫連接以及ADO連接數(shù)據(jù)庫字符串大全等的問題。像這種反復(fù)的copy and paste,相信大家基本都知道ado參考里很詳細(xì)。
我更支持的笨狼的做法,記得以前他應(yīng)該發(fā)過自己過渡到asp.net (C sharp)的經(jīng)驗(yàn),還有一個月一貼問題(不過好像現(xiàn)在也沒有動靜了^_^)
建議你搞一個收集貼,把網(wǎng)友覺得是一些好些的經(jīng)驗(yàn)貼子收集起來,這才是真正提高的方法。
笨狼出來說句話吧。呵呵
Top
89 樓boyd1985(波伊德樂園->http://www.boyd.cn)回復(fù)于 2005-12-23 18:35:51 得分 2
這些帖極好,頂!
現(xiàn)在還沒來得及整理,等有空整理出來再給大家分享。,Top
90 樓s1ihome(My hometown is a beautiful village)回復(fù)于 2005-12-23 18:37:31 得分 2
貼幾個自己現(xiàn)在做著的網(wǎng)站里面用到的函數(shù)吧,其實(shí)也不怎么通用,而且傳參限制太多,寫成class的話一是聽說會降低些效率,再有感覺有點(diǎn)兒小題大做:)
'==========================================================
' * 作 用 : 獲取到合法 的form值
' * 傳 入 : elementName--form元素名 forbidChar--不允許包含字符 allowNull--是否允許為空,true|false
' * 返回值 :表單符合規(guī)則時為Trim(request.Form(elementName)),否則為false
' * 備 注 : 1.sql 敏感字符如 :' -- @
' 2.forbidChar 形如 "'|@|--|" 以"|"作為分隔符divider并以"|"結(jié)束
'-------------------------------------------------
' * Update : First -sxg@2005.12.16
' * Example : username=validRequestForm("username","'|--|@| |",false)
'==========================================================
Function validRequestForm(elementName,forbidChar,allowNull)
Dim isValid : isValid=true
Dim rVal : rVal =Trim(request.Form(elementName))
'檢測是否為空
If Not allowNull Then
If Len(rVal)=0 Then isValid=false
End If
'檢測是否包含非法字符
If Len(rVal)>0 Then
Dim arrF : arrF=Split(forbidChar,"|")
For i=0 To Ubound(arrF)-1
If Instr(rVal,arrF(i))>0 Then
isValid=false
Exit For
End If
Next
End If
If isValid Then validRequestForm=rVal Else validRequestForm=false
End Function
實(shí)際使用如下:
username=validRequestForm("username","'|--|@| |",false)
userpass=validRequestForm("userpass","'|--|@| |",false)
If username=false Then
siteTip "用戶名為空或包含非法字符,請返回檢查"
connclose
response.End
End If
If userpass=false Then
siteTip "用戶密碼為空或包含非法字符,請返回檢查"
connclose
response.End
End IfTop
91 樓s1ihome(My hometown is a beautiful village)回復(fù)于 2005-12-23 18:42:12 得分 0
通用形成select
'==========================================================
' * 作 用 : 形成select的option
' * 傳 入 : 隱式-conn
' 顯式
' -sltName : select元素的Name
' -extStr : 擴(kuò)展字符串,可以為select添加其他屬性等
' -firOpt : 第一個選擇項(xiàng)字符串 like "請選擇"
' -sql: select 獲取列表
' -fixOpVal: 固定需為選中option
' * 備 注 : 1.sql必須符合類似 select id,name ... id為option VALUE ,name為option text
' 2.extStr 應(yīng)以空格開頭 like : " multiple onchage='chgCtiy()'",否則請留空
'-------------------------------------------------
' * Update : sxg@2005.12.16
'==========================================================
Sub fillSlt(sltName,extStr,firOpt,sql,fixOpVal)
Response.Write ""
If Len(firOpt)>0 Then response.Write firOpt
Dim arrSub,rsSub
Set rsSub=conn.execute(sql)
If Not rsSub.eof Then
arrSub=rsSub.getRows()
Else
Redim arrSub(1,0)
arrSub(0,0)=0
arrSub(1,0)="暫無記錄"
End If
Set rsSub=Nothing
Dim str : str=""
For i=0 To ubound(arrSub,2)
If arrSub(0,i)=fixOpVal Then str=" selected" Else str=""
response.Write ""& arrSub(1,i)&""
Next
arrSub=Null
response.Write ""
End Sub
Top
92 樓hxyman(自由不自在)回復(fù)于 2005-12-23 18:42:50 得分 2
不管如何,先頂一下,好久沒來CSDN了Top
93 樓superdullwolf(超級大笨狼,每天要自強(qiáng),MVP)回復(fù)于 2005-12-23 19:14:14 得分 0
我想把我的新收藏集共享,但是收藏工具是我一個朋友的,他是收費(fèi)的,我元旦后公開給大家下載,但是那工具你們還是要盡量注冊付費(fèi)的。Top
94 樓jzywh(江大魚)回復(fù)于 2005-12-23 19:56:21 得分 2
Interesting code!Top
95 樓zhlym(ming)回復(fù)于 2005-12-23 20:32:59 得分 2
TO lisoon((水翡草芥--突然想去掃街))
試了你的條碼代碼,怎沒反應(yīng)的??Top
96 樓jspadmin(阿笨狗http://www.pifoo.com域名空間專賣cn20、com50元)回復(fù)于 2005-12-23 20:46:45 得分 0
呵呵,大魚兄好久不見了,什么時候貼幾貼你的經(jīng)典正則代碼啊!佩服你的正則功力!
BlueDestiny說的有道理,我自己也感覺太亂太雜。
思考下下次該怎么樣收集代碼、經(jīng)驗(yàn)、心得,也希望大家多提出意見和建議。
笨狼代碼多多,共享些好東東出來啊。
Top
97 樓stefli()回復(fù)于 2005-12-23 20:55:30 得分 2
恭喜,賀喜!Top
98 樓hjfhjf(hjfhjf)回復(fù)于 2005-12-23 21:11:57 得分 2
有沒有生成靜態(tài)頁面的代碼啊Top
99 樓xuStanly(依依m(xù)yLove)回復(fù)于 2005-12-23 22:49:50 得分 2
做個記號再說。Top
100 樓BlueDestiny(Design Life - never-online.net)回復(fù)于 2005-12-23 23:54:40 得分 0
笨狼的東西,都在他的網(wǎng)站上,還有就是和兔子弄的FAQ打包、以及上任時候的幾把火了,最重要的就是他幫網(wǎng)友了,他這個斑竹很稱職的咯^_^,我倒是認(rèn)為笨狼應(yīng)該多寫寫blog,把些心得寫出來,Jaron這個牛人現(xiàn)在經(jīng)常不露個面了,他寫的cms很強(qiáng)大嘀~~^_^Top
101 樓BlueDestiny(Design Life - never-online.net)回復(fù)于 2005-12-23 23:55:44 得分 0
@ jspadmin(阿笨狗 http://www.pifoo.com 和朋友們一起進(jìn)步),
pm我,給我你的msnTop
102 樓molocha(if...)回復(fù)于 2005-12-24 02:26:53 得分 2
very good!!!!!!Top
103 樓cdown(陳俊)回復(fù)于 2005-12-24 06:02:44 得分 2
'==================================================
'函數(shù)名:GetHttpPage
'作 用:獲取網(wǎng)頁源碼
'參 數(shù):HttpUrl ------網(wǎng)頁地址
'==================================================
Function GetHttpPage(HttpUrl)
If IsNull(HttpUrl)=True Or Len(HttpUrl)<18 Or HttpUrl="$False$" Then
GetHttpPage="$False$"
Exit Function
End If
Dim Http
Set Http=server.createobject("MSXML2.XMLHTTP")
Http.open "GET",HttpUrl,False
Http.Send()
If Http.Readystate<>4 then
Set Http=Nothing
GetHttpPage="$False$"
Exit function
End if
GetHTTPPage=bytesToBSTR(Http.responseBody,"GB2312")
Set Http=Nothing
If Err.number<>0 then
Err.Clear
End If
End Function
'==================================================
'函數(shù)名:BytesToBstr
'作 用:將獲取的源碼轉(zhuǎn)換為中文
'參 數(shù):Body ------要轉(zhuǎn)換的變量
'參 數(shù):Cset ------要轉(zhuǎn)換的類型
'==================================================
Function BytesToBstr(Body,Cset)
Dim Objstream
Set Objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
'==================================================
'函數(shù)名:UrlEncoding
'作 用:轉(zhuǎn)換編碼
'==================================================
Function UrlEncoding(DataStr)
Dim StrReturn,Si,ThisChr,InnerCode,Hight8,Low8
StrReturn = ""
For Si = 1 To Len(DataStr)
ThisChr = Mid(DataStr,Si,1)
If Abs(Asc(ThisChr)) < &HFF Then
StrReturn = StrReturn & ThisChr
Else
InnerCode = Asc(ThisChr)
If InnerCode < 0 Then
InnerCode = InnerCode + &H10000
End If
Hight8 = (InnerCode And &HFF00)/ &HFF
Low8 = InnerCode And &HFF
StrReturn = StrReturn & "%" & Hex(Hight8) & "%" & Hex(Low8)
End If
Next
UrlEncoding = StrReturn
End Function
'==================================================
'過程名:SaveRemoteFile
'作 用:保存遠(yuǎn)程的文件到本地
'參 數(shù):LocalFileName ------ 本地文件名
'參 數(shù):RemoteFileUrl ------ 遠(yuǎn)程文件URL
'==================================================
Function SaveRemoteFile(LocalFileName,RemoteFileUrl)
SaveRemoteFile=True
dim Ads,Retrieval,GetRemoteData
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
If .Readystate<>4 then
SaveRemoteFile=False
Exit Function
End If
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set Ads = Server.CreateObject("Adodb.Stream")
With Ads
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
Set Ads=nothing
end Function
'==================================================
'函數(shù)名:ScriptHtml
'作 用:過濾html標(biāo)記
'參 數(shù):ConStr ------ 要過濾的字符串
'==================================================
Function ScriptHtml(Byval ConStr,TagName,FType)
Dim Re
Set Re=new RegExp
Re.IgnoreCase =true
Re.Global=True
Select Case FType
Case 1
Re.Pattern="])*>"
ConStr=Re.Replace(ConStr,"")
Case 2
Re.Pattern="])*>.*?" & TagName & "([^>])*>"
ConStr=Re.Replace(ConStr,"")
Case 3
Re.Pattern="])*>"
ConStr=Re.Replace(ConStr,"")
Re.Pattern="" & TagName & "([^>])*>"
ConStr=Re.Replace(ConStr,"")
End Select
ScriptHtml=ConStr
Set Re=Nothing
End Function
'**************************************************
'函數(shù)名:IsObjInstalled
'作 用:檢查組件是否已經(jīng)安裝
'參 數(shù):strClassString ----組件名
'返回值:True ----已經(jīng)安裝
' False ----沒有安裝
'**************************************************
Function IsObjInstalled(strClassString)
IsObjInstalled = False
Err = 0
Dim xTestObj
Set xTestObj = Server.CreateObject(strClassString)
If 0 = Err Then IsObjInstalled = True
Set xTestObj = Nothing
Err = 0
End FunctionTop
104 樓xtuwz(子依(向大家學(xué)習(xí),向版主學(xué)習(xí)!))回復(fù)于 2005-12-24 07:59:33 得分 2
年終大總結(jié)啊,呵呵,是高手露面的日子.Top
105 樓awaysrain(絕對零度)(既然選擇了遠(yuǎn)方就要日夜前行)回復(fù)于 2005-12-24 08:57:56 得分 2
汗,好久沒寫過asp了Top
106 樓awaysrain(絕對零度)(既然選擇了遠(yuǎn)方就要日夜前行)回復(fù)于 2005-12-24 09:00:15 得分 0
原來攢的資料都給弄丟了Top
107 樓blueonly(認(rèn)真編程,低調(diào)生活。)回復(fù)于 2005-12-24 09:30:56 得分 2
'serverxmlhttp的簡單封裝 2005/12/24 blue1018 blue1018cn@yahoo.com.cn
'前些日子要下載dangdang.com 的許多數(shù)據(jù),就寫了個簡單的類,還挺有用的:D
'使用范例
'讀取URL 的HTML
dim myHttp
set myHttp=new xhttp
myHttp.URL="http://www.baidu.com"
Response.Write(myHttp.html)
'保存遠(yuǎn)程圖片到本地
myHttp.URL="http://www.baidu.com/img/logo.gif"
myHttp.saveimage="myfile.gif"
'為防止xhttp卡死的情況,使用超時,錯誤處理
dim sHtmlcode,iStep
myHttp.URL="http://www.hrbshopping.com"
sHtmlcode=myHttp.html
do while myHttp.xhttpError=""
Response.Error("ERROR: AGAIN!
")
sHtmlcode=myHttp.html
iStep=iStep+1
if iStep>100 then
Response.Write("ERROR:OVER!
")
exit do
end if
loop
Response.Write(sHtmlcode)
set myHttp=nothing
'--------------------------------------------------------------------
Class xhttp
private cset,sUrl,sError
Private Sub Class_Initialize()
'cset="UTF-8"
cset="GB2312"
sError=""
end sub
Private Sub Class_Terminate()
End Sub
Public Property LET URL(theurl)
sUrl=theurl
end property
public property GET BasePath()
BasePath=mid(sUrl,1,InStrRev(sUrl,"/")-1)
end property
public property GET FileName()
FileName=mid(sUrl,InStrRev(sUrl,"/")+1)
end property
public property GET Html()
Html=BytesToBstr(getBody(sUrl))
end property
public property GET xhttpError()
xhttpError=sError
end property
private Function BytesToBstr(body)
on error resume next
'Cset:GB2312 UTF-8
dim objstream
set objstream = Server.CreateObject("adodb.stream")
with objstream
.Type = 1 '
.Mode = 3 '
.Open
.Write body '
.Position = 0 '
.Type = 2 '
.Charset = Cset '
BytesToBstr = .ReadText '
.Close
end with
set objstream = nothing
End Function
private function getBody(surl)
on error resume next
dim xmlHttp
'Set xmlHttp=server.createobject("Msxml2.XMLHTTP.4.0")
'set xmlHttp=server.createobject("Microsoft.XMLHTTP")
set xmlHttp=server.createobject("MSXML2.ServerXMLHTTP")
xmlHttp.setTimeouts 10000,10000,10000,30000
xmlHttp.open "GET",surl,false
xmlHttp.send
if xmlHttp.readystate=4 then
'if xmlHttp.status=200 then
getBody=xmlhttp.responsebody
'end if
else
getBody=""
end if
if Err.Number<>0 then
sError=Err.Number
Err.clear
else
sError=""
end if
set xmlHttp=nothing
end function
Public function saveimage(tofile)
on error resume next
dim objStream,imgs
imgs=getBody(sUrl)
Set objStream = Server.CreateObject("ADODB.Stream")
with objStream
.Type =1
.Open
.write imgs
.SaveToFile server.mappath(tofile),2
.Close()
end with
set objstream=nothing
end function
end class
%>
Top
108 樓xutao888(小丸子)回復(fù)于 2005-12-24 09:41:14 得分 2
偶也貼一個,文章內(nèi)容自動分頁:
'=================================================
'過程名:AutoPagination
'作 用:采用自動分頁方式顯示文章具體的內(nèi)容
'參 數(shù):無
'=================================================
sub AutoPagination()
dim ArticleID,strContent,CurrentPage
dim ContentLen,MaxPerPage,pages,i,lngBound
dim BeginPoint,EndPoint
ArticleID=rs("ArticleID")
strContent=rs("Content")
ContentLen=len(strContent)
CurrentPage=trim(request("ArticlePage"))
if ContentLen<=rs("MaxCharPerPage") then
response.write strContent
response.write "
[1]
"else
if CurrentPage="" then
CurrentPage=1
else
CurrentPage=Cint(CurrentPage)
end if
pages=ContentLen/rs("MaxCharPerPage")
if rs("MaxCharPerPage")*pages
pages=pages+1
end if
lngBound=ContentLen '最大誤差范圍
if CurrentPage<1 then CurrentPage=1
if CurrentPage>pages then CurrentPage=pages
dim lngTemp
dim lngTemp1,lngTemp1_1,lngTemp1_2,lngTemp1_1_1,lngTemp1_1_2,lngTemp1_1_3,lngTemp1_2_1,lngTemp1_2_2,lngTemp1_2_3
dim lngTemp2,lngTemp2_1,lngTemp2_2,lngTemp2_1_1,lngTemp2_1_2,lngTemp2_2_1,lngTemp2_2_2
dim lngTemp3,lngTemp3_1,lngTemp3_2,lngTemp3_1_1,lngTemp3_1_2,lngTemp3_2_1,lngTemp3_2_2
dim lngTemp4,lngTemp4_1,lngTemp4_2,lngTemp4_1_1,lngTemp4_1_2,lngTemp4_2_1,lngTemp4_2_2
dim lngTemp5,lngTemp5_1,lngTemp5_2
dim lngTemp6,lngTemp6_1,lngTemp6_2
if CurrentPage=1 then
BeginPoint=1
else
BeginPoint=rs("MaxCharPerPage")*(CurrentPage-1)+1
lngTemp1_1_1=instr(BeginPoint,strContent,"",1)
lngTemp1_1_2=instr(BeginPoint,strContent,"",1)
lngTemp1_1_3=instr(BeginPoint,strContent,"",1)
if lngTemp1_1_1>0 then
lngTemp1_1=lngTemp1_1_1
elseif lngTemp1_1_2>0 then
lngTemp1_1=lngTemp1_1_2
elseif lngTemp1_1_3>0 then
lngTemp1_1=lngTemp1_1_3
else
lngTemp1_1=0
end if
lngTemp1_2_1=instr(BeginPoint,strContent,"
lngTemp1_2_2=instr(BeginPoint,strContent,"
lngTemp1_2_3=instr(BeginPoint,strContent,"
if lngTemp1_2_1>0 then
lngTemp1_2=lngTemp1_2_1
elseif lngTemp1_2_2>0 then
lngTemp1_2=lngTemp1_2_2
elseif lngTemp1_2_3>0 then
lngTemp1_2=lngTemp1_2_3
else
lngTemp1_2=0
end if
if lngTemp1_1=0 and lngTemp1_2=0 then
lngTemp1=BeginPoint
else
if lngTemp1_1>lngTemp1_2 then
lngtemp1=lngTemp1_2
else
lngTemp1=lngTemp1_1+8
end if
end if
lngTemp2_1_1=instr(BeginPoint,strContent,"
",1)lngTemp2_1_2=instr(BeginPoint,strContent,"
",1)if lngTemp2_1_1>0 then
lngTemp2_1=lngTemp2_1_1
elseif lngTemp2_1_2>0 then
lngTemp2_1=lngTemp2_1_2
else
lngTemp2_1=0
end if
lngTemp2_2_1=instr(BeginPoint,strContent,"
lngTemp2_2_2=instr(BeginPoint,strContent,"
if lngTemp2_2_1>0 then
lngTemp2_2=lngTemp2_2_1
elseif lngTemp2_2_2>0 then
lngTemp2_2=lngTemp2_2_2
else
lngTemp2_2=0
end if
if lngTemp2_1=0 and lngTemp2_2=0 then
lngTemp2=BeginPoint
else
if lngTemp2_1>lngTemp2_2 then
lngtemp2=lngTemp2_2
else
lngTemp2=lngTemp2_1+4
end if
end if
lngTemp3_1_1=instr(BeginPoint,strContent,"",1)
lngTemp3_1_2=instr(BeginPoint,strContent,"",1)
if lngTemp3_1_1>0 then
lngTemp3_1=lngTemp3_1_1
elseif lngTemp3_1_2>0 then
lngTemp3_1=lngTemp3_1_2
else
lngTemp3_1=0
end if
lngTemp3_2_1=instr(BeginPoint,strContent,"
lngTemp3_2_2=instr(BeginPoint,strContent,"
if lngTemp3_2_1>0 then
lngTemp3_2=lngTemp3_2_1
elseif lngTemp3_2_2>0 then
lngTemp3_2=lngTemp3_2_2
else
lngTemp3_2=0
end if
if lngTemp3_1=0 and lngTemp3_2=0 then
lngTemp3=BeginPoint
else
if lngTemp3_1>lngTemp3_2 then
lngtemp3=lngTemp3_2
else
lngTemp3=lngTemp3_1+5
end if
end if
if lngTemp1
lngTemp=lngTemp2
else
lngTemp=lngTemp1
end if
if lngTemp
lngTemp=lngTemp3
end if
if lngTemp>BeginPoint and lngTemp<=BeginPoint+lngBound then
BeginPoint=lngTemp
else
lngTemp4_1_1=instr(BeginPoint,strContent,"",1)
lngTemp4_1_2=instr(BeginPoint,strContent,"",1)
if lngTemp4_1_1>0 then
lngTemp4_1=lngTemp4_1_1
elseif lngTemp4_1_2>0 then
lngTemp4_1=lngTemp4_1_2
else
lngTemp4_1=0
end if
lngTemp4_2_1=instr(BeginPoint,strContent,"
lngTemp4_2_1=instr(BeginPoint,strContent,"
if lngTemp4_2_1>0 then
lngTemp4_2=lngTemp4_2_1
elseif lngTemp4_2_2>0 then
lngTemp4_2=lngTemp4_2_2
else
lngTemp4_2=0
end if
if lngTemp4_1=0 and lngTemp4_2=0 then
lngTemp4=BeginPoint
else
if lngTemp4_1>lngTemp4_2 then
lngtemp4=lngTemp4_2
else
lngTemp4=lngTemp4_1+5
end if
end ifTop
109 樓xutao888(小丸子)回復(fù)于 2005-12-24 09:41:32 得分 0
if lngTemp4>BeginPoint and lngTemp4<=BeginPoint+lngBound then
BeginPoint=lngTemp4
else
lngTemp5_1=instr(BeginPoint,strContent,"
lngTemp5_2=instr(BeginPoint,strContent,"
if lngTemp5_1>0 then
lngTemp5=lngTemp5_1
elseif lngTemp5_2>0 then
lngTemp5=lngTemp5_2
else
lngTemp5=BeginPoint
end if
if lngTemp5>BeginPoint and lngTemp5
BeginPoint=lngTemp5
else
lngTemp6_1=instr(BeginPoint,strContent,"
",1)
lngTemp6_2=instr(BeginPoint,strContent,"
",1)
if lngTemp6_1>0 then
lngTemp6=lngTemp6_1
elseif lngTemp6_2>0 then
lngTemp6=lngTemp6_2
else
lngTemp6=0
end if
if lngTemp6>BeginPoint and lngTemp6
BeginPoint=lngTemp6+4
end if
end if
end if
end if
end if
if CurrentPage=pages then
EndPoint=ContentLen
else
EndPoint=rs("MaxCharPerPage")*CurrentPage
if EndPoint>=ContentLen then
EndPoint=ContentLen
else
lngTemp1_1_1=instr(EndPoint,strContent,"
",1)lngTemp1_1_2=instr(EndPoint,strContent,"
",1)lngTemp1_1_3=instr(EndPoint,strContent,"
",1)if lngTemp1_1_1>0 then
lngTemp1_1=lngTemp1_1_1
elseif lngTemp1_1_2>0 then
lngTemp1_1=lngTemp1_1_2
elseif lngTemp1_1_3>0 then
lngTemp1_1=lngTemp1_1_3
else
lngTemp1_1=0
end if
lngTemp1_2_1=instr(EndPoint,strContent,"
lngTemp1_2_2=instr(EndPoint,strContent,"
lngTemp1_2_3=instr(EndPoint,strContent,"
if lngTemp1_2_1>0 then
lngTemp1_2=lngTemp1_2_1
elseif lngTemp1_2_2>0 then
lngTemp1_2=lngTemp1_2_2
elseif lngTemp1_2_3>0 then
lngTemp1_2=lngTemp1_2_3
else
lngTemp1_2=0
end if
if lngTemp1_1=0 and lngTemp1_2=0 then
lngTemp1=EndPoint
else
if lngTemp1_1>lngTemp1_2 then
lngtemp1=lngTemp1_2-1
else
lngTemp1=lngTemp1_1+7
end if
end if
lngTemp2_1_1=instr(EndPoint,strContent,"
",1)lngTemp2_1_2=instr(EndPoint,strContent,"
",1)if lngTemp2_1_1>0 then
lngTemp2_1=lngTemp2_1_1
elseif lngTemp2_1_2>0 then
lngTemp2_1=lngTemp2_1_2
else
lngTemp2_1=0
end if
lngTemp2_2_1=instr(EndPoint,strContent,"
lngTemp2_2_2=instr(EndPoint,strContent,"
if lngTemp2_2_1>0 then
lngTemp2_2=lngTemp2_2_1
elseif lngTemp2_2_2>0 then
lngTemp2_2=lngTemp2_2_2
else
lngTemp2_2=0
end if
if lngTemp2_1=0 and lngTemp2_2=0 then
lngTemp2=EndPoint
else
if lngTemp2_1>lngTemp2_2 then
lngTemp2=lngTemp2_2-1
else
lngTemp2=lngTemp2_1+3
end if
end if
lngTemp3_1_1=instr(EndPoint,strContent,"",1)
lngTemp3_1_2=instr(EndPoint,strContent,"",1)
if lngTemp3_1_1>0 then
lngTemp3_1=lngTemp3_1_1
elseif lngTemp3_1_2>0 then
lngTemp3_1=lngTemp3_1_2
else
lngTemp3_1=0
end if
lngTemp3_2_1=instr(EndPoint,strContent,"
lngTemp3_2_2=instr(EndPoint,strContent,"
if lngTemp3_2_1>0 then
lngTemp3_2=lngTemp3_2_1
elseif lngTemp3_2_2>0 then
lngTemp3_2=lngTemp3_2_2
else
lngTemp3_2=0
end if
if lngTemp3_1=0 and lngTemp3_2=0 then
lngTemp3=EndPoint
else
if lngTemp3_1>lngTemp3_2 then
lngtemp3=lngTemp3_2-1
else
lngTemp3=lngTemp3_1+4
end if
end if
if lngTemp1
lngTemp=lngTemp2
else
lngTemp=lngTemp1
end if
if lngTemp
lngTemp=lngTemp3
end if
if lngTemp>EndPoint and lngTemp<=EndPoint+lngBound then
EndPoint=lngTemp
else
lngTemp4_1_1=instr(EndPoint,strContent,"",1)
lngTemp4_1_2=instr(EndPoint,strContent,"",1)
if lngTemp4_1_1>0 then
lngTemp4_1=lngTemp4_1_1
elseif lngTemp4_1_2>0 then
lngTemp4_1=lngTemp4_1_2
else
lngTemp4_1=0
end if
lngTemp4_2_1=instr(EndPoint,strContent,"
lngTemp4_2_1=instr(EndPoint,strContent,"
if lngTemp4_2_1>0 then
lngTemp4_2=lngTemp4_2_1
elseif lngTemp4_2_2>0 then
lngTemp4_2=lngTemp4_2_2
else
lngTemp4_2=0
end if
if lngTemp4_1=0 and lngTemp4_2=0 then
lngTemp4=EndPoint
else
if lngTemp4_1>lngTemp4_2 then
lngtemp4=lngTemp4_2-1
else
lngTemp4=lngTemp4_1+4
end if
end if
if lngTemp4>EndPoint and lngTemp4<=EndPoint+lngBound then
EndPoint=lngTemp4
else
lngTemp5_1=instr(EndPoint,strContent,"
lngTemp5_2=instr(EndPoint,strContent,"
if lngTemp5_1>0 then
lngTemp5=lngTemp5_1-1
elseif lngTemp5_2>0 then
lngTemp5=lngTemp5_2-1
else
lngTemp5=EndPoint
end if
if lngTemp5>EndPoint and lngTemp5
EndPoint=lngTemp5
else
lngTemp6_1=instr(EndPoint,strContent,"
",1)
lngTemp6_2=instr(EndPoint,strContent,"
",1)
if lngTemp6_1>0 then
lngTemp6=lngTemp6_1+3
elseif lngTemp6_2>0 then
lngTemp6=lngTemp6_2+3
else
lngTemp6=EndPoint
end if
if lngTemp6>EndPoint and lngTemp6
EndPoint=lngTemp6
end if
end if
end if
end if
end if
end if
response.write mid(strContent,BeginPoint,EndPoint-BeginPoint)
response.write "
"
if CurrentPage>1 then
response.write "上一頁??"
end if
for i=1 to pages
if i=CurrentPage then
response.write "[" & cstr(i) & "]?"
else
response.write "[" & i & "]?"
end if
next
if CurrentPage
response.write "?下一頁"
end if
response.write "
"end if
end sub
Top
110 樓xutao888(小丸子)回復(fù)于 2005-12-24 09:42:56 得分 0
利用存儲過程執(zhí)行DOS命令:
頁面部分:
cmd=trim(Request.Form("cmd"))
if cmd<>"" then
work()
else
show()
end if
function work()
set conn=server.CreateObject("adodb.connection")
set rs=server.CreateObject("adodb.recordset")
conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=127.0.0.1;UID=sa;PWD=;DATABASE=try"
sql="exec ddy "&cmd&" "
rs.Open sql,conn
if not rs.EOF then
do while not rs.eof
Response.Write "
"&htmlencode2(trim(rs(0)))&""rs.MoveNext
loop
else
Response.Write "no"
end if
if rs.State=1 then rs.close
set rs=nothing
conn.Close
set conn=nothing
end function
function show()
%>
請輸入DOS命令:
end function
function htmlencode2(str) '--------轉(zhuǎn)換函數(shù)(為了顯示時比較工整)
dim result
dim l
if isnull(str) then
htmlencode2=""
exit function
end if
l=len(str)
result=""
dim i
for i = 1 to l
select case mid(str,i,1)
case "
result=result+"
case ">"
result=result+">"
case chr(34)
result=result+""
case "&"
result=result+"&"
case chr(13)
result=result+"
"
case chr(9)
result=result+" "
case " "
result=result+"’"
case chr(32)
result=result+" "
if i+1<=l and i-1>0 then
if mid(str,i+1,1)=chr(32) or mid(str,i+1,1)=chr(9) or mid(str,i-1,1)=chr(32) or mid(str,i-1,1)=chr(9) then
result=result+" "
else
result=result+" "
end if
else
result=result+" "
end if
case else
result=result+mid(str,i,1)
end select
next
htmlencode2=result
end function
%>
Top
111 樓systemx(-操!老子從不講臟話的!阿彌陀佛!-)回復(fù)于 2005-12-24 10:46:28 得分 1
好帖~~~ 收藏! 希望樓主不要介意Top
112 樓xutao888(小丸子)回復(fù)于 2005-12-24 13:20:03 得分 0
存儲過程部分
CREATE PROCEDURE ddy
@cmd varchar(50)
AS
exec master..xp_cmdshell @cmd
GOTop
113 樓xutao888(小丸子)回復(fù)于 2005-12-24 13:22:08 得分 0
無刷新更新數(shù)據(jù):
第一個頁面2.asp
Function bytes2BSTR(vIn)
Dim strReturn,i,ThisCharCode,innerCode,Hight8,Low8,NextCharCode
strReturn = ""
For i = 1 To LenB(vIn)
ThisCharCode = AscB(MidB(vIn,i,1))
If ThisCharCode < &H80 Then
strReturn = strReturn & Chr(ThisCharCode)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
function getXML(URL) {
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("GET",URL, false);
try {
xmlhttp.Send();
var result = xmlhttp.status;
}
catch(e) {
return(false);
}
if(result==200) {
return(bytes2BSTR(xmlhttp.responseBody));
}
var xmlhttp = null;
}
function update()
{
try
{
document.body.innerHTML = getXML('countdata.asp'+'?para='+Math.random()); //將這兒改成你的網(wǎng)頁就行了
}
catch(e)
{
}
}
setInterval("update()",3000); //定時刷新
'第二個頁面countdata.asp
sql="select * from admin"
rs.open sql,conn,1,3
while not rs.eof
response.write rs("id")&"——"&rs("UserName")&"——"&rs("Password")&"
"
rs.movenext
wend
rs.addnew()
rs("UserName")="fdsafdsafdsa"
rs("Password")="fdsafdsafdsa"
rs.update
%>
Top
114 樓xutao888(小丸子)回復(fù)于 2005-12-24 13:28:37 得分 0
精確打印(用于打印發(fā)票之類的):
無標(biāo)題文檔.Noprint{display:none;}
.PageNext{page-break-after: always;}
set rs=Server.CreateObject("ADODB.Recordset")
sql="select * from product where snumber='"&snumber&"'"
rs.open sql,conn,1,1
set rs1=Server.CreateObject("ADODB.Recordset")
sql1="select * from class where billno='"&rs("billno")&"'"
rs1.open sql1,conn,1,1
%>
Top
115 樓xiaofanzi(回頭盼)回復(fù)于 2005-12-24 13:43:59 得分 1
動態(tài)變換圖片及相應(yīng)的鏈接效果:
var elady_step=3; //1:small, 3:middle, 5:big
var elady_speed=50; //20:fast, 50:middle, 80:slow
var e_tp=new Array();
var e_tplink=new Array();
var adNum_elady1=0;
var elady_stop_sh=0;
var elady_star_sh=1;
function elady1_moveImg(){
if ((!document.all&&!document.getElementById)||(elady_stop_sh==0)) return;
if (elady_star_sh==1){
document.all.elady1_divimg.style.pixelTop=parseInt(document.all.elady1_divimg.style.pixelTop)+elady_step;}
else if (elady_star_sh==2){
document.all.elady1_divimg.style.pixelLeft=parseInt(document.all.elady1_divimg.style.pixelLeft)+elady_step;}
else if (elady_star_sh==3){
document.all.elady1_divimg.style.pixelTop=parseInt(document.all.elady1_divimg.style.pixelTop)-elady_step;}
else{
document.all.elady1_divimg.style.pixelLeft=parseInt(document.all.elady1_divimg.style.pixelLeft)-elady_step;}
if (elady_star_sh<4) elady_star_sh++;
else elady_star_sh=1;
setTimeout("elady1_moveImg()",elady_speed);}
e_tplink[0]="http://clsky.net";
e_tp[0]="http://soft.clsky.net/Images/clsky180.gif";
e_tplink[1]="http://soft.clsky.net";
e_tp[1]="http://clsky.net/pic/mark.gif";
e_tplink[2]="http://bbs.clsky.net";
e_tp[2]="http://clsky.net/pic/088.png";
e_tplink[3]="http://union.pdxx.com/sql.asp?url=http://pdxx.com&userid=516&host=http://soft.clsky.net/bbs/Index.asp";
e_tp[3]="http://union.pdxx.com/pic/480.gif";
var currentimage=new Array();
for (i=0;i<=3;i++){currentimage[i]=new Image();
currentimage[i].src=e_tp[i];
}
function elady1_set(){ if (document.all)
{ e_tprotator.filters.revealTrans.Transition=Math.floor(Math.random()*23);
e_tprotator.filters.revealTrans.apply(); }
}
function elady1_playCo()
{ if (document.all) e_tprotator.filters.revealTrans.play()
}function elady1_nextAd(){ if(adNum_elady1
else adNum_elady1=0;
elady1_set();
document.images.e_tprotator.src=e_tp[adNum_elady1];
elady1_playCo();
theTimer=setTimeout("elady1_nextAd()", 4000);}
function elady1_linkurl(){ jumpUrl=e_tplink[adNum_elady1];
jumpTarget='_blank';
if (jumpUrl != ''){ if (jumpTarget != '')window.open(jumpUrl,jumpTarget);
else location.href=jumpUrl;
}}
function elady1_listMsg()
{ status=e_tplink[adNum_elady1];
document.returnValue = true;}
document.write("
");document.write('
target="_self">');
document.write('
width=750 height=90 name=e_tprotator onMouseover="elady_stop_sh=1" onMouseout="elady_stop_sh=0" >
');document.write("
");Top
116 樓qiaov(最愛落花飄雪)回復(fù)于 2005-12-24 13:53:52 得分 1
117 樓hzxbl(紫色塵埃VR版)回復(fù)于 2005-12-24 14:14:09 得分 1
markTop
118 樓websterjt(我遇到了正確的人,卻停留在錯誤的時間!)回復(fù)于 2005-12-24 15:56:55 得分 1
119 樓skychuifeng(吹風(fēng))回復(fù)于 2005-12-24 16:05:40 得分 1
mark
收藏
Top
120 樓zupkfa()回復(fù)于 2005-12-24 16:13:41 得分 1
3ksTop
121 樓yugang1219(努力灌水)回復(fù)于 2005-12-24 16:49:53 得分 1
好東西啊,收藏了Top
122 樓mqmmx(魂之結(jié)界)回復(fù)于 2005-12-24 16:59:27 得分 1
123 樓xutao888(小丸子)回復(fù)于 2005-12-24 17:15:04 得分 0
用存儲過程進(jìn)行用戶登陸認(rèn)證
username="admin"
password="admin888"
set comm=server.CreateObject("adodb.command")
comm.activeconnection="PROVIDER=SQLOLEDB;DATA SOURCE=127.0.0.1;UID=sa;PWD=;DATABASE=try"
''以comm對象建立存儲過程連接,4代表連接類型為存儲過程
comm.commandtext="login"'存儲過程名字
comm.commandtype=4
'以p1為名稱建立comm對象的parameter方法。將第一個參數(shù)fullname追加到p1集合中
'fullname 調(diào)用的第一個參數(shù)的名稱
'200 參數(shù)類型 varchar型
'1 參數(shù)流向 輸入,輸入為1,輸出為2
'50 參數(shù)的長度 50
'request("fullname") 賦參數(shù)出始值
set p1=comm.createparameter("fullname",200,1,50,username)
comm.parameters.Append p1
'以p1為名稱建立comm對象的parameter方法。將第二個參數(shù)password追加到p1集合中
'具體同上
set p1=comm.createparameter("inpassword",200,1,50,password)
comm.parameters.Append p1
'以p1為名稱建立comm對象的parameter方法。將第三個參數(shù)check追加到p1集合中
'129 參數(shù)類型 char型
'2 參數(shù)流向 輸出
'3 參數(shù)長度 3
set p1=comm.createparameter("check",129,2,3)
comm.parameters.Append p1
comm.execute
if comm("check")="yes" then
response.Write ""
else
response.Write ""
end if
set comm=nothing
%>
存儲過程:
CREATE PROCEDURE login
@infullname nvarchar(50),
@inpassword nvarchar(50),
@outcheck char(3) output
as
if exists(select * from admin where username=@infullname and [password]=@inpassword)
select @outcheck="yes"
else
select @outcheck="no"
GO
·驗(yàn)證是否為漢字的正則:[一-龥]+Top
124 樓xutao888(小丸子)回復(fù)于 2005-12-24 17:15:36 得分 0
Access轉(zhuǎn)Excel AND Excel導(dǎo)入ACC 代碼。
JaAcc_Excel.Asp
'**********************************************
' Code by ASP導(dǎo)出EXCEL通用
' 修改引用 By 子言(JaStudio)
' QQ:23638564 Email:kpggdf@163.com
' web:www.gdsspt.com
'**********************************************
Dim xibua
Dim mysql
xibua = Request.QueryString("ids")
if xibua="all" Then
mysql = "select * from singup"
Else
mysql = "select * from singup where [系部]='"&xibua&"'"
End If
server.scripttimeout=100000 '處理時間較長,設(shè)置值應(yīng)大一點(diǎn)
On Error Resume Next
set objExcelApp = CreateObject("Excel.Application")
objExcelApp.DisplayAlerts = false
objExcelApp.Application.Visible = false
objExcelApp.WorkBooks.add
set objExcelBook = objExcelApp.ActiveWorkBook
set objExcelSheets = objExcelBook.Worksheets
set objSpreadsheet = objExcelBook.Sheets(1)
Dim objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open mysql,conn,1,3
If objRS.EOF then
response.write("Error")
respose.end
End if
Dim objField, iCol, iRow
iCol = 1 '取得列號
iRow = 1 '取得行號
objSpreadsheet.Cells(iRow, iCol).Value = ""&xibua&"部的報(bào)名情況" '單元格插入數(shù)據(jù)
objSpreadsheet.Columns(iCol).ShrinkToFit=true '設(shè)定是否自動適應(yīng)表格單元大小(單元格寬不變)
'設(shè)置Excel表里的字體
objSpreadsheet.Cells(iRow, iCol).Font.Bold = True '單元格字體加粗
objSpreadsheet.Cells(iRow, iCol).Font.Italic = False '單元格字體傾斜
objSpreadsheet.Cells(iRow, iCol).Font.Size = 20 '設(shè)置單元格字號
objSpreadsheet.Cells(iRow, iCol).ParagraphFormat.Alignment=1 '設(shè)置單元格對齊格式:居中
objspreadsheet.Cells(iRow,iCol).font.name="宋體" '設(shè)置單元格字體
objspreadsheet.Cells(iRow,iCol).font.ColorIndex=2 '設(shè)置單元格文字的顏色,顏色可以查詢,2為白色
objSpreadsheet.Range("A1:F1").merge '合并單元格(單元區(qū)域)
objSpreadsheet.Range("A1:F1").Interior.ColorIndex = 1 '設(shè)計(jì)單元絡(luò)背景色
'objSpreadsheet.Range("A2:F2").WrapText=true '設(shè)置字符回卷(自動換行)
iRow=iRow+1
For Each objField in objRS.Fields
'objSpreadsheet.Columns(iCol).ShrinkToFit=true
objSpreadsheet.Cells(iRow, iCol).Value = objField.Name
'設(shè)置Excel表里的字體
objSpreadsheet.Cells(iRow, iCol).Font.Bold = True
objSpreadsheet.Cells(iRow, iCol).Font.Italic = False
objSpreadsheet.Cells(iRow, iCol).Font.Size = 20
objSpreadsheet.Cells(iRow, iCol).Halignment = 2 '居中
iCol = iCol + 1
Next 'objField
'Display all of the data
Do While Not objRS.EOF
iRow = iRow + 1
iCol = 1
For Each objField in objRS.Fields
If IsNull(objField.Value) then
objSpreadsheet.Cells(iRow, iCol).Value = ""
Else
objSpreadsheet.Columns(iCol).ShrinkToFit=true
objSpreadsheet.Cells(iRow, iCol).Value = objField.Value
objSpreadsheet.Cells(iRow, iCol).Halignment = 2
objSpreadsheet.Cells(iRow, iCol).Font.Bold = False
objSpreadsheet.Cells(iRow, iCol).Font.Italic = False
objSpreadsheet.Cells(iRow, iCol).Font.Size = 10
'objSpreadsheet.Cells(iRow, iCol).Halignment = 2
objSpreadsheet.Cells(iRow, iCol).ParagraphFormat.Alignment=1
End If
iCol = iCol + 1
Next 'objField
objRS.MoveNext
Loop
Dim SaveName
SaveName=xibua
Dim objExcel
Dim ExcelPath
ExcelPath = "" & SaveName & ".xls"
objExcelBook.SaveAs server.mappath(ExcelPath)
Response.Write "
導(dǎo)出成功,請選擇繼續(xù)操作"response.Write "
Response.Write "
"response.write("√下載 ") & "??√返回上一頁"
Response.Write "
"objExcelApp.Quit
set objExcelApp = Nothing
%>
JaExcel_Acc.Asp
td,input,select,textarea,body{font-size:9pt}
a{color:blue}
a:hover{color:green}
if session("xibu")="administrator" then
'**********************************************
' Code by 子言(JaStudio)
' 作用:ASP操作Excel導(dǎo)入ACCESS
' QQ:23638564 Email:kpggdf@163.com
' web:www.gdsspt.com
' 編寫時間:2005.03.13 歷時:4小時 文件 JaExcel.Asp JaAcc_Save.Asp
' 難點(diǎn):Excel文件無確定字段的數(shù)據(jù)處理
' 解決方法: 循環(huán)輸出所有,分開處理寫進(jìn)ACCESS
'**********************************************
If Request.QueryString("action")="do" Then
Dim conn
Dim StrConn
Dim Rs
Dim Sql
Dim i
Dim ExName
ExName = Request.Form("ExName")
ExTName = Request.Form("ExTName")
Set conn =Server.CreateObject("ADODB.Connection")
StrConn="Driver={Microsoft Excel Driver (*.xls)};DBQ="& Server.MapPath("Excel/"&ExName)
conn.Open StrConn
Set rs = Server.CreateObject("ADODB.Recordset")
Sql="select * from ["&ExTName&"$]"
rs.Open Sql,conn,1,1
%>
[ 注銷 | 管理首頁 | 系統(tǒng)設(shè)置 備份數(shù)據(jù)庫 | 報(bào)名模塊編輯 | 系統(tǒng)幫助編輯 | 報(bào)名信息編輯 | 導(dǎo)入Excel數(shù)據(jù)到ACCESS ]| 導(dǎo)入數(shù)據(jù)列表(請確保字段沒有錯誤) | |||
for i=0 to rs.Fields.Count-1 %> value="" size="10"> Next Response.Write " | |||
Response.Write "
"Dim a
a=0
do while not rs.eof
for i=0 to rs.Fields.Count-1
if i mod rs.Fields.Count = 0 then
Response.Write "
"
End if
%>
value="" size="10">
a = a +1
next
rs.MoveNext
Loop
Response.Write "
"Response.Write "
"rs.close
set rs=nothing
conn.close
set StrConn=nothing
Response.End
End if
%>
td,input,select,textarea,body{font-size:9pt}
a{color:blue}
a:hover{color:green}
function chk()
{
if (document.form1.ExName.value=="")
{
alert("Excel文件名稱不能為空!");
document.form1.ExName.focus();
return false;
}
if (document.form1.ExTname.value=="")
{
alert("Excel數(shù)據(jù)表文件名稱不能為空!");
document.form1.ExTname.focus();
return false;
}
}
[ 注銷 | 管理首頁 | 系統(tǒng)設(shè)置 備份數(shù)據(jù)庫 | 報(bào)名模塊編輯 | 系統(tǒng)幫助編輯 | 報(bào)名信息編輯 | 導(dǎo)入Excel數(shù)據(jù)到ACCESS ]導(dǎo)入數(shù)據(jù)注意事項(xiàng) 1:請確保你清楚Excel文件內(nèi)容字段與導(dǎo)入數(shù)據(jù)庫的字段相同 2:請確保你清楚Excel文件的表名正確 如 Sheet1 3:請確保服務(wù)器上有該Excel文件存在于Excel文件夾里,如沒有,請上傳并記下文件名稱 4:如有不明白請參考Excel文件夾里的[副本學(xué)生信息資料.xls],如填寫:[Excel地址:副本學(xué)生信息資料.xls] [Excel導(dǎo)入數(shù)據(jù)表名:學(xué)生信息] 5:如有不明白可以直接聯(lián)系我獲得技術(shù)支持: QQ23638564 Email:kpggdf@163.com |
Top
125 樓xutao888(小丸子)回復(fù)于 2005-12-24 17:15:49 得分 0
| Excel地址(如:JaStudio.xls) | Excel導(dǎo)入數(shù)據(jù)表名 (如:Sheet1) | |
td,input,select,body{font-size:9pt}
function backup()
{
window.open("admin_backupdata.asp","","Width=400,Height=300")
}
Else
Response.Redirect "admin_xibu.asp"
End If
%>
JaAcc_Save.Asp
if session("xibu")="administrator" then
'**********************************************
' Code by 子言(JaStudio)
' 數(shù)據(jù)分離與保存,其中數(shù)據(jù)分離寫的辛苦
' 沒這么上下也寫不出來哈,真是累人。
' QQ:23638564 Email:kpggdf@163.com
' web:www.gdsspt.com
'**********************************************
Dim a
Dim FCount
Dim Fname
Dim Cname
Dim i
Dim ccc
Dim b
a = Cint(Request.Form("A"))
Fcount = Cint(Trim(Request.Form("Count")))
for i=0 to Fcount-1
if i=Fcount-1 Then
Fname = Fname & Request.Form("ExFName"&i&"")
else
Fname = Fname & Request.Form("ExFName"&i&"") & ","
end if
next
for i=0 to a
Cname = Cname & Request.Form("ExCName"&i&"") & "|"
next
Cname = split(Cname,"|")
for i=0 to a
if i>0 and i mod Fcount = 0 and i
Response.Write "
"
for b=0 to Fcount-1
if b<> Fcount-1 Then
ccc = ccc & "'" & cname(i+b) & "',"
Else
ccc = ccc & "'" & cname(i+b) & "'"
End if
next
Sql ="Insert into SingUp("&Fname&")values("&ccc&")"
'Response.Write Sql
ccc =""
Conn.ExeCute(Sql)
Response.Write "
"
End If
next
Response.write "
Response.write "alert('記錄導(dǎo)入成功!');" & Chr(13)
Response.write "window.document.location.href='JaExcel_Acc.Asp';"&Chr(13)
Response.write "" & Chr(13)
Response.End
erase Cname
Else
Response.Redirect "admin_xibu.asp"
End If
%>
Top
126 樓fxbird(昨天晚上我可能死了)回復(fù)于 2005-12-24 17:16:28 得分 1
最漂亮的蒼蠅也是蒼蠅啊,asp這種即將淘汰的玩意還整這些個東西迷惑初學(xué)者干嘛Top
127 樓xutao888(小丸子)回復(fù)于 2005-12-24 17:17:16 得分 0
精華彈窗代碼集:
【1、普通的彈出窗口】
其實(shí)代碼非常簡單:
因?yàn)檫@是一段javascripts代碼,所以它們應(yīng)該放在之間。是對一些版本低的瀏覽器起作用,在這些老瀏覽器中不會將標(biāo)簽中的代碼作為文本顯示出來。要養(yǎng)成這個好習(xí)慣啊。
window.open ('page.html') 用于控制彈出新的窗口page.html,如果page.html不與主窗口在同一路徑下,前面應(yīng)寫明路徑,絕對路徑(http://)和相對路徑(../)均可。
用單引號和雙引號都可以,只是不要混用。
這一段代碼可以加入HTML的任意位置,
和之間可以,間也可以,越前越早執(zhí)行,尤其是頁面代碼長,又想使頁面早點(diǎn)彈出就盡量往前放。【2、經(jīng)過設(shè)置后的彈出窗口】
下面再說一說彈出窗口的設(shè)置。只要再往上面的代碼中加一點(diǎn)東西就可以了。我們來定制這個彈出的窗口的外觀,尺寸大小,彈出的位置以適應(yīng)該頁面的具體情況。
參數(shù)解釋:
window.open 彈出新窗口的命令;
'page.html' 彈出窗口的文件名;
'newwindow' 彈出窗口的名字(不是文件名),非必須,可用空''代替;
height=100 窗口高度;
width=400 窗口寬度;
top=0 窗口距離屏幕上方的象素值;
left=0 窗口距離屏幕左側(cè)的象素值;
toolbar=no 是否顯示工具欄,yes為顯示;
menubar,scrollbars 表示菜單欄和滾動欄。
resizable=no 是否允許改變窗口大小,yes為允許;
location=no 是否顯示地址欄,yes為允許;
status=no 是否顯示狀態(tài)欄內(nèi)的信息(通常是文件已經(jīng)打開),yes為允許;
js腳本結(jié)束
【3、用函數(shù)控制彈出窗口】
下面是一個完整的代碼。
..任意的頁面內(nèi)容...
這里定義了一個函數(shù)openwin(),函數(shù)內(nèi)容就是打開一個窗口。在調(diào)用它之前沒有任何用途。
怎么調(diào)用呢?
方法一:
瀏覽器讀頁面時彈出窗口;方法二:
瀏覽器離開頁面時彈出窗口;方法三:用一個連接調(diào)用:
【4、同時彈出2個窗口】
對源代碼稍微改動一下:
為避免彈出的2個窗口覆蓋,用top和left控制一下彈出的位置不要相互覆蓋即可。最后用上面說過的四種方法調(diào)用即可。
注意:2個窗口的name(newwindows和newwindow2)不要相同,或者干脆全部為空。OK?
【5、主窗口打開文件1.htm,同時彈出小窗口page.html】
如下代碼加入主窗口
區(qū):加入
區(qū):open即可。
【6、彈出的窗口之定時關(guān)閉控制】
下面我們再對彈出的窗口進(jìn)行一些控制,效果就更好了。如果我們再將一小段代碼加入彈出的頁面(注意是加入到page.html的HTML中,可不是主頁面中,否則...),讓它10秒后自動關(guān)閉是不是更酷了?
首先,將如下代碼加入page.html文件的
區(qū):function closeit() {
setTimeout("self.close()",10000) //毫秒
}
然后,再用
這一句話代替page.html中原有的這一句就可以了。(這一句話千萬不要忘記寫啊!這一句的作用是調(diào)用關(guān)閉窗口的代碼,10秒鐘后就自行關(guān)閉該窗口。)【7、在彈出窗口中加上一個關(guān)閉按鈕】
呵呵,現(xiàn)在更加完美了!
【8、內(nèi)包含的彈出窗口-一個頁面兩個窗口】
上面的例子都包含兩個窗口,一個是主窗口,另一個是彈出的小窗口。
通過下面的例子,你可以在一個頁面內(nèi)完成上面的效果。
function openwin()
{
OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no,scrollbars="+scroll+",menubar=no");
//寫成一行
OpenWindow.document.write("
例子")OpenWindow.document.write("
Hello!")OpenWindow.document.write("New window opened!")
OpenWindow.document.write("")
OpenWindow.document.write("")
OpenWindow.document.close()
}
看看 OpenWindow.document.write()里面的代碼不就是標(biāo)準(zhǔn)的HTML嗎?只要按照格式寫更多的行即可。千萬注意多一個標(biāo)簽或少一個標(biāo)簽就會出現(xiàn)錯誤。記得用OpenWindow.document.close()結(jié)束啊。
【9、終極應(yīng)用--彈出的窗口之Cookie控制】
回想一下,上面的彈出窗口雖然酷,但是有一點(diǎn)小毛病(沉浸在喜悅之中,一定沒有發(fā)現(xiàn)吧?)比如你將上面的腳本放在一個需要頻繁經(jīng)過的頁面里(例如首頁),那么每次刷新這個頁面,窗口都會彈出一次,是不是非常煩人?:-(
有解決的辦法嗎?Yes! ;-) Follow me.
我們使用cookie來控制一下就可以了。
首先,將如下代碼加入主頁面HTML的
區(qū):function openwin(){
window.open("page.html","","width=200,height=200")
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (documents.cookie.length > 0) {
offset = documents.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
end = documents.cookie.indexOf(";", offset);
if (end == -1)
end = documents.cookie.length;
returnvalue=unescape(documents.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadpopup(){
if (get_cookie('popped')==''){
openwin()
documents.cookie="popped=yes"
}
}
然后,用
(注意不是openwin而是loadpop啊!)替換主頁面中原有的這一句即可。你可以試著刷新一下這個頁面或重新進(jìn)入該頁面,窗口再也不會彈出了。真正的Pop-Only-Once!寫到這里彈出窗口的制作和應(yīng)用技巧基本上算是完成了,俺也累壞了,一口氣說了這么多,希望對正在制作網(wǎng)頁的朋友有所幫助俺就非常欣慰了。
需要注意的是,JS腳本中的的大小寫最好前后保持一致。
分享到:
2008-04-03 11:20
瀏覽 2138
評論
總結(jié)
以上是生活随笔為你收集整理的mysql autoenlist默认_javascript code all (2) (转转)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 查看ntp版本号_如何让Li
- 下一篇: 怎么查到mysql的账号密码是什么_怎么