?? database.asp
字號(hào):
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage=65001%>
<%Response.Charset="utf-8"%>
<%
'sql_odbc_connection(database,username,password) 'SQL Server數(shù)據(jù)庫用ODBC連接數(shù)據(jù)庫方式
'sql_general_connection(database,username,password) 'SQL Server數(shù)據(jù)庫普通連接方式
'access_connection(database_name) 'Access數(shù)據(jù)庫連接方式
'close_data_connection() '關(guān)閉數(shù)據(jù)庫連接
'data_operation(sql) '對(duì)數(shù)據(jù)庫里的數(shù)據(jù)進(jìn)行刪除,修改,添加
'get_data(sql) '從數(shù)據(jù)庫中取出單條數(shù)據(jù)或取出一組數(shù)據(jù)
'conversion_content(content) '把數(shù)據(jù)庫中的內(nèi)容轉(zhuǎn)換成有回車,有空格的內(nèi)容
'pagination(strSql,page_size) '分頁顯示數(shù)據(jù)
dim conn'把conn聲明為全局變量
'調(diào)用連接數(shù)據(jù)庫函數(shù)
database_name=""
database=""
username=""
password=""
'call sql_odbc_connection(database,username,password)
'call sql_general_connection(database,username,password)
'call access_connection(database_name)
'------------------------------------------------------------------------
'SQL Server數(shù)據(jù)庫用ODBC連接數(shù)據(jù)庫方式
sub sql_odbc_connection(database,username,password)
set conn=server.createobject("adodb.Connection")
conn.open "dsn="&database&";uid="&username&";pwd="&password&""
end sub
'------------------------------------------------------------------------
'SQL Server數(shù)據(jù)庫普通連接方式
'(數(shù)據(jù)庫連接初始化)
sub conn_init(database,username,password)
connstr = "database="&database&";uid="&username&";pwd="&password&";server=localhost;provider=sqloledb;"
on error resume next
set conn=server.createobject("ADODB.conNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "數(shù)據(jù)庫連接出錯(cuò)!"
Response.End
else
conn.open connstr
if err then
err.clear
set conn=nothing
response.write "數(shù)據(jù)庫連接出錯(cuò)!!!!"
Response.End
end if
end if
end sub
'(數(shù)據(jù)庫連接)
sub sql_general_connection(database,username,password)
dim conn
dim connstr
call conn_init(database,username,password)
end sub
'------------------------------------------------------------------------
'Access數(shù)據(jù)庫連接方式
sub access_connection(database_name)
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(database_name)
set conn=server.createobject("adodb.connection")
conn.open connstr
end sub
'------------------------------------------------------------------------
'關(guān)閉數(shù)據(jù)庫連接
sub close_data_connection()
conn.close
set conn=nothing
end sub
'------------------------------------------------------------------------
'對(duì)數(shù)據(jù)庫里的數(shù)據(jù)進(jìn)行刪除,修改,添加
function data_operation(sql)
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn,1,3
'response.write sql
'檢測數(shù)據(jù)操作是否成功
if conn.errors.count>0 then
data_operation=0'失敗
else
data_operation=1'成功
end if
end function
function data_operation2(sql)
set rs=Server.CreateObject("ADODB.Recordset")
rs.execute sql
'檢測數(shù)據(jù)操作是否成功
if conn.errors.count>0 then
data_operation=0'失敗
else
data_operation=1'成功
end if
end function
'------------------------------------------------------------------------
'從數(shù)據(jù)庫中取出單條數(shù)據(jù)或取出一組數(shù)據(jù)
function get_data(sql)
set get_data=Server.CreateObject("ADODB.Recordset")
get_data.Open sql,conn,1,1
end function
'------------------------------------------------------------------------
'把數(shù)據(jù)庫中的內(nèi)容轉(zhuǎn)換成有回車,有空格的內(nèi)容
function conversion_content(content)
conversion_content=content
if conversion_content<>"" then
conversion_content=replace(conversion_content," "," ")
conversion_content=replace(conversion_content,chr(13)+chr(10),"<br>")
end if
end function
public function my_replace(InputStr) '對(duì)單個(gè)字符進(jìn)行輪換
InputStr=Replace(InputStr,"'",".")
my_replace=inputstr
end function
public function my_backplace(InputStr) '對(duì)單個(gè)字符進(jìn)行輪換
InputStr=Replace(InputStr,".","'")
my_backplace=inputstr
end function
'------------------------------------------------------------------------
'分頁顯示數(shù)據(jù)
sub pagination(strSql,page_size)
response.write "<table width=100% border=0 cellspacing=0 cellpadding=0>"
set rs=Server.CreateObject("ADODB.Recordset")
'判斷傳過來的數(shù)是否為空
pagenum=request.querystring("pagenum")
if pagenum="" then
pagenum=1
else
pagenum=cint(pagenum)
end if
rs.CursorType = 1
rs.CacheSize = 30
rs.Open strSql,conn,1,1
rs.PageSize = page_size
'控制下標(biāo)的范圍
pagecount=rs.pagecount
if pagenum<1 then pagenum=1
if pagenum>rs.pagecount then pagenum=pagecount
if(rs.recordCount<>0)then
rs.AbsolutePage =pagenum
'輸出各個(gè)字段相對(duì)應(yīng)的值
for j=1 to rs.pagesize
response.write "<tr><td height=27>"&rs("title")&"</td></tr>"
rs.moveNext
if rs.eof then exit for
next
response.write "<tr><td height=27>"
'作為分頁
if pagenum=1 then
response.write "上一頁"
else
response.write "<a href=?pagenum="&pagenum-1&">上一頁</a>"
end if
response.write "   "
if pagenum=pagecount then
response.write "下一頁"
else
response.write "<a href=?pagenum="&pagenum+1&">下一頁</a>"
end if
'顯示出當(dāng)前頁是總頁數(shù)的第幾頁
response.write "   "
response.write pagenum&"/"&pagecount
response.write "   "
response.write "</td></tr>"
end if
response.write "</table>"
end sub
'----------------------------------------------------------------------------------------------
'介紹FileSystem組件(提示:在返回值是多個(gè)或不知是何種類型時(shí)用這種方式:set countfile=myfolder.files,然后用:for each fd in countfile)
'set myfile_eob = server.createObject("scripting.FileSystemObject") '創(chuàng)建一個(gè)fileSystem對(duì)象
'set myfile = myfile_eob.createTextFile("d:\my.txt") '創(chuàng)建一個(gè)文件,并起名為my.txt
'myfile.writeLine("hello world") '向文件中寫入一行字
'myfile.writeblanklines '寫入一空行
'myfile.fileExists("d:\my.txt")'檢測是否存在,返回值是True或False
'set myfile = myfile_eob.openTextFile("d:\my.txt",1,false) '打開已存在的文件,1表示只讀(默認(rèn)),2表示寫,8表示追加
'thisLine = myfile.readline '讀取文件中一行內(nèi)容
' myfile.read(n) '讀取文件中n個(gè)字符
' myfile.readAll '讀取文件中所有的內(nèi)容
' myfile.skip(n) '讀取文件時(shí),跳過n個(gè)字符
' myfile.skipLine(n)'讀取文件時(shí),跳過n行
'AtEndOfLine '判斷當(dāng)前字符是否處于文件中一行的行末
'AtEndOfStream '判斷當(dāng)前字符是否處于文件的結(jié)尾
'myfile_eob.copyFile sourceFile destinationFile overwrite 'overwrite表示在文件存在的情況下,進(jìn)行覆蓋
'myfile_eob.moveFile sourceFile destinationFile '移動(dòng)文件
'myfile_eob.deleteFile fileName '刪除文件
'set newfile = myfile.getFile("d:\my.txt") '取得文件對(duì)象實(shí)例
'newfile.dateCreated '返回文件創(chuàng)建的日期和時(shí)間
'newfile.dateLastAccessed '返回文件上次被使用的日期和時(shí)間
'newfile.dateLastModified '返回文件上次被修改的日期和時(shí)間
'newfile.driver '返回文件所在的驅(qū)動(dòng)器
'newfile.name '返回文件名
'newfile.parentFloder '返回文件所在的文件夾
'newfile.path '返回文件的完整路徑
'newfile.size '返回文件的大小
'newfile.type '返回文件的類型
'對(duì)文件夾的操作
'myfile_eob.copyFolder soureFile destinationFile overwrite '文件夾的復(fù)制
'myfile_eob.createFolder folderName '創(chuàng)建一個(gè)文件夾
'myfile_eob.deleteFolder folderName '刪除一個(gè)文件夾
'myfile_eob.moveFolder sourceFile destinationFile '移動(dòng)文件夾
'set thisFolder = myfile_eob.getFolder("d:\my") '創(chuàng)建一個(gè)文件夾對(duì)象
'thisFolder.files '返回當(dāng)前目錄下的所有文件(隱藏文件除外)
'thisFolder.isRootFolder '返回值表示是否為根目錄
'thisFolder.parentFolder '返回上一級(jí)目錄
'thisFolder.subFolders '當(dāng)前目錄下所有子目錄的集合
%>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -