n(valPrefix) )
Response.Write "<Select ...>" & vbNewLine
Response.Write valPrefix & opts
Response.Write "</Select>"
%>
如果想建立一个正确的表格的话,解决那个BUG,只要这样做就可以了:
复制代码 代码如下:
<%
Set RS = conn.Execute("Select * FROM table")
tdSuffix = "</TD>" & vbNewLine & "<TD>
trPrefix = "<TR>" & vbNewLine & "<TD>"
trSuffix = "</TD>" & vbNewLine & "</TR>" & vbNewLine & "<TR>" & vbNewLine
opts = RS.GetString( , , tdSuffix, trSuffix & trPrefix, "--error--" )
'' Next line is the key to it!
opts = Left( opts, Len(opts)-Len(trPrefix) )
Response.Write "<TABLE Border=1 CellPadding=5>" & vbNewLine
Response.Write trPrefix & opts
Response.Write "</TABLE>" & vbNewLine
%>
再介绍一个完全不同的办法:
复制代码 代码如下:
<%
SQL = "Select ''<OPTION Value='''''',value,''''''>'',text,''</OPTION>'' FROM table orDER BY text"
Set RS = conn.Execute(SQL)
Response.Write "<Select>" & vbNewLine & RS.GetString(,,"",vbNewLine) & "</Select>"
%>
你用过吗。。。
看到了吗?可以直接从
查询中返回结果。
再进一步,您可以这样做:
复制代码 代码如下:
<%
SQL = "Select ''<OPTION Value='''''' & value & ''''''>'' & text & ''</OPTION>'' FROM table orDER BY text"
Set RS = conn.Execute(SQL)
Response.Write "<Select>" & vbNewLine & RS.GetString(,,"",vbNewLine) & "</Select>"
%>
下面是一份完整的示例:
Script Output:
711855 Wednesday 23 3/23/2005 1:33:37 AM
711856 Wednesday 23 3/23/2005 1:23:00 AM
711857 Wednesday 23 3/23/2005 1:26:34 AM
711858 Wednesday 23 3/23/2005 1:33:53 AM
711859 Wednesday 23 3/23/2005 1:30:36 AM
ASP完整代码如下:
复制代码 代码如下:
<%
'' Selected constants from adovbs.inc:
Const adClipString = 2
'' Declare our variables... always good practice!
Dim cnnGetString '' ADO connection
Dim rstGetString '' ADO recordset
Dim strDBPath '' Path to our Access DB (*.mdb) file
Dim strDBData '' String that we dump all the data into
Dim strDBDataTable '' String that we dump all the data into
'' only this time we build a table
'' MapPath to our mdb file''s physical path.
strDBPath = Server.MapPath("db_scratch.mdb")
'' Create a Connection using OLE DB
Set cnnGetString = Server.CreateObject("ADODB.Connection")
'' This line is for the Access sample database:
''cnnGetString.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"
'' We''re actually using SQL Server so we use this line instead.
'' Comment this line out and uncomment the Access one above to
'' play with the script on your own server.
cnnGetString.Open "Provider=SQLOLEDB;Data Source=10.2.1.214;" _
& "Initial Catalog=samples;User Id=samples;Password=password;" _
& "Connect Timeout=15;Network Library=dbmssocn;"
'' Execute a simple query using the connection object.
'' Store the resulting recordset in our variable.
Set rstGetString = cnnGetString.Execute("Select * FROM scratch")
'' Now this is where it gets interesting... Normally we''d do
'' a loop of some sort until we r