《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.返回数据集函数 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文件中读取数据 <!-- 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中的数据,可以指定颜色和样式 //接口函数 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 } //方法实现 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)) |
|