《ASP編程大全》
1.提取字段列表
//<%
Set cn=Server.CreateObject("ADODB.Connection")
cn.Open "Provider=SQLOLEDB;Data Source=localhost;" & _
"Initial Catalog=pubs;User ID=sa;Password="
Set rs=cn.Execute("Select * from authors")
While Not rs.EOF
Response.Write rs("au_fname")
rs.MoveNext
Wend
rs.Close
cn.Close
//%>
2.返回數(shù)據(jù)集函數(shù)
Public Function GetData() As ADODB.Recordset
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Set cn=CreateObject("ADODB.Connection")
cn.Open "Provider=SQLOLEDB;Data Source=localhost;" & _
"Initial Catalog=pubs;User ID=sa;Password="
Set rs=CreateObject("ADODB.Connection")
rs.LockType=adLockBatchOptimistic
rs.CursorLocation=adUseClient
rs.CursorType=adOpenStatic
rs.Open "Select * from authors",cn
Set rs.ActiveConnection=Nothing
cn.Close
Set cn=Nothing
Set GetData=http://blog.soso.com/qz.q/rs
End Function
3.從XML文件中讀取數(shù)據(jù)
<!-- Metadata type="typelib" file="c:program filescommon filessystemadomsado15.dll"-->
<%
'response.write admoderead & " " & adopenstreamfromurl
'response.End()
set rs = server.CreateObject("adodb.recordset")
Set stmData = http://blog.soso.com/qz.q/Server.CreateObject("ADODB.Stream")
stmData.Charset="gb2312"'這一句很重要,否則會報一個錯誤。Recordset cannot be created from the specified source. The source file or stream must contain Recordset data in XML or ADTG format.移山祝大家好運^_^
xmbm = request.QueryString("xmbm")
if xmbm = "" then xmbm = "110100001"
Dim result
dim xml, XMLlength
Set DCOMServer = CreateObject("RemObjects.SDK.COMServer")
DCOMServer.MessageType = "TROBINMessage"
DCOMServer.ChannelType = "TROWinInetHTTPChannel"
DCOMServer.SetChannelProperty "TargetURL", "http://192.168.1.119:8089/BIN"
Set DCOMService = DCOMServer.CreateService("DCOMService")
xml = cstr("<?xml version="&chr(34)&"1.0"&chr(34)&" encoding="&chr(34)&"gb2312"&chr(34)&" ?>" & chr(13)&chr(10))
xml = xml & cstr(DCOMService.GetItem(xmbm))'用于生成XML主體的DCOM服務,實際中請靈活運用。
Set MegaDemoService = nothing
'response.write xml
'response.End()
stmData.Open
stmData.WriteText xml
stmData.SetEOS
'stmData.SaveToFile server.MapPath("zzzz"&session.SessionID&".xml"),2
'response.End()
stmData.Position = 0
rs.open stmData
if not rs.eof then
response.write "<table border = 1 cellpadding=5 cellspacing=0 bordercolor=black style='border-collapse:collapse;'><tr bgcolor='#ddddeee'>"
for each fld in rs.fields
response.write "<td>" & fld.name & "</td>"
next
response.write "</tr>"
do while not rs.eof
response.write "<tr>"
for each fld in rs.fields
response.write "<td>" & fld.value & "</td>"
next
response.write "</tr>"
rs.movenext
loop
end if
rs.close
set rs = nothing
%>
自動顯示RecordSet的表格
<script language=jscript runat=server>
// ************************************************** **********************
// Script Compont Object Model
// Design for Active Server Pages
//
// Copyright 2003 Version 1.0
// Made by 尹曙光
// ************************************************** **********************
//用于顯示一個recordset中的數(shù)據(jù),可以指定顏色和樣式
//接口函數(shù)
function createJDBList(){
var objJDBlist=new JDBlist
objJDBlist.create()
return objJDBlist
}
//類體定義
function JDBlist(){
this.AdoRecordSet
this.Width
this.Border
this.Cellspacing
this.Cellpadding
this.Class
this.TitleClass
this.FirstColor
this.SecondColor
this.create=_JDBlist_Create
this.display=_JDBlist_Display
}
//方法實現(xiàn)
function _JDBlist_Create(){
this.AdoRecordSet=""
this.Width="100%"
this.Border="1"
this.Cellspacing="0"
this.Cellpadding="1"
this.Class=""
this.TitleClass=''
this.FirstColor=''
this.SecondColor=''
}
function _JDBlist_Display(){
var htmlDSO = '';
var nFields = this.AdoRecordSet.Fields.Count;
if (nFields)
{
var n = 0;
htmlDSO += '<' + 'table width="'+this.Width+'" id="'+this.Id+'" Cellspacing="'+this.Cellspacing+'" Cellpadding="'+this.Cellpadding+'" Border="'+this.Border+'" Class="'+this.Class+'">n';
htmlDSO += '<' + 'tr>';
for (var i=0; i < nFields; i++)
{
htmlDSO += '<' + 'td class="'+this.TitleClass+'">' + this.AdoRecordSet(i).name + '<' + '/td>';
}
htmlDSO += '<' + '/tr>n';
if (!(this.AdoRecordSet.EOF&&this.AdoRecordSet.Bof))
本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請
點擊舉報。