从数据库中检索记录并将其以特定格式写入文件
我不太熟悉 asp 经典函数,尽管我现在正在使用一个 .asp 文件,该文件在下拉菜单中的 java 脚本 onChange 事件上显示来自 SQL 数据库的记录。我想要实现的是以下面的格式显示这些记录,并将所有记录写入文本文件,而无需通过 java 脚本调用,即使是从下拉菜单中也是如此。
这是我到目前为止正在处理的问题:
<!--#include virtual="/includes/functions.asp" -->
<%
intBusiness_Catagory = Request("select_catagory")
Set thisConn = Server.CreateObject("ADODB.Connection")
thisConn.Open CreateAfccDSN()
SelectSQL = "SELECT * FROM BusinessInfo WHERE ((CatID = " & intBusiness_Catagory & ") or (CatID2 = " & intBusiness_Catagory & ") or (CatID3 = " & intBusiness_Catagory & ")) and (intStatusCodeID = 1) and (intOnWeb = 1) Order By vcBusinessName"
Set SelectRs = thisConn.Execute(SelectSQL)
If SelectRs.EOF Then
Response.Write("No members found for selected category.<br> Please search <a href='javascript:history.back()'>again</a>.")
Else
%>
<b>Member Search Results:</b>
<p>
<%
End If
If Not SelectRs.BOF AND Not SelectRs.EOF then
SelectRs.MoveFirst
Do Until SelectRs.EOF
%>
<b><%=SelectRs("vcBusinessName") %></b><br>
<%=SelectRs("vcPhone") %><br>
<%=SelectRs("vcPAddress") %><br>
<%=SelectRs("vcPCity") %>, <%=SelectRs("vcPState") %> <%=SelectRs("vcPZipCode") %><br>
<%
If isNull(SelectRs("vcURL")) then
Else
%>
<b>Website: </b><a href="http://<%=SelectRs("vcURL") %>" target="_blank"><%=SelectRs("vcURL") %></a>
<%
End If
%>
<p>
<hr>
<%
SelectRs.MoveNext
Loop
%>
<%
End If
SelectRs.Close
Set SelectRs = Nothing
%>
<p style="text-align: right"><small><a href="business_directory_framed.asp">Back to directory index</a></small></p>
任何人都可以协助解决这个问题吗?谢谢。
I am not really familiar with asp-classic functions, though i am now working with a .asp file that displays records from a SQL database upon a java-script onChange event in a drop-down menu. What I'm trying to achieve is to display these records in the format below, and for all of them to be written to a text file without being called through java-script even from the drop-down menu.
Here's what I'm working with so far:
<!--#include virtual="/includes/functions.asp" -->
<%
intBusiness_Catagory = Request("select_catagory")
Set thisConn = Server.CreateObject("ADODB.Connection")
thisConn.Open CreateAfccDSN()
SelectSQL = "SELECT * FROM BusinessInfo WHERE ((CatID = " & intBusiness_Catagory & ") or (CatID2 = " & intBusiness_Catagory & ") or (CatID3 = " & intBusiness_Catagory & ")) and (intStatusCodeID = 1) and (intOnWeb = 1) Order By vcBusinessName"
Set SelectRs = thisConn.Execute(SelectSQL)
If SelectRs.EOF Then
Response.Write("No members found for selected category.<br> Please search <a href='javascript:history.back()'>again</a>.")
Else
%>
<b>Member Search Results:</b>
<p>
<%
End If
If Not SelectRs.BOF AND Not SelectRs.EOF then
SelectRs.MoveFirst
Do Until SelectRs.EOF
%>
<b><%=SelectRs("vcBusinessName") %></b><br>
<%=SelectRs("vcPhone") %><br>
<%=SelectRs("vcPAddress") %><br>
<%=SelectRs("vcPCity") %>, <%=SelectRs("vcPState") %> <%=SelectRs("vcPZipCode") %><br>
<%
If isNull(SelectRs("vcURL")) then
Else
%>
<b>Website: </b><a href="http://<%=SelectRs("vcURL") %>" target="_blank"><%=SelectRs("vcURL") %></a>
<%
End If
%>
<p>
<hr>
<%
SelectRs.MoveNext
Loop
%>
<%
End If
SelectRs.Close
Set SelectRs = Nothing
%>
<p style="text-align: right"><small><a href="business_directory_framed.asp">Back to directory index</a></small></p>
Anyone can assist with a solution to this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需将 SQL 结果转储到已有的 adodb 记录集中,然后循环记录集并使用 fso com 对象写入 csv 文件。
示例代码(未经测试)
You'd simply dump the results of your SQL into an adodb recordset as you already have, then loop through the recordset and write the csv file using the fso com object.
Example Code (untested)