2016-10-02 57 views
0

我試圖從「選擇」語句中提取特定元素以便填寫網站上的表格。我將使用經典ASP。查找記錄集中的特定元素,經典ASP

例如,我的s​​elect語句返回這些值;

名稱ID 亞歷Alex123現在

,在我的網頁,我希望表是這個樣子,

名暱稱ID地址 亞歷克斯「輸入字段」 Alex123「輸入字段」

在我的html代碼中,我期待着做這樣的事情。我怎樣才能做到這一點?

<tr> 
<td> "some code to extract "Alex" from the recordset"</td> 
<td> <input blalbalba> </td> 
<td> "some code to extract "Alex123" from the recordset"</td> 
<td> <input blabalba> </td> 
</tr> 

下面是我的連接字符串和我的select語句。

Set Con = CreateObject("ADODB.Connection") 
Con.ConnectionString = "Provider=SQLOLEDB;Data Source=YOONGTAT\SQLEXPRESS;Database=testing;User ID=sa;password=1234" 
Con.open 

set rs=Server.CreateObject("ADODB.Recordset") 
rs.Open "Select * from dbo.exampletable where user_name like '%" & Request.Form("employeeName[]")(i) & "%' and user_id like '%" & Request.Form("employeeId[]")(i) & "%'" , con 
+0

這可能是你要找的東西:http://stackoverflow.com/questions/13405736/classic-asp-to-pull-data-from-database –

回答

0

你只需要遍歷記錄,拿出你的任何字段值興趣,並與相應的HTML打印它們在線。像這樣的應該做的伎倆:

<table> 
    <thead> 
    <tr> 
     <th>Name</th> 
     <th>Nickname</th> 
     <th>ID</th> 
     <th>Address</th> 
    </tr> 
    </thead> 
<% 
    rs.Open "Select * from dbo.exampletable where user_name like '%" & Request.Form("employeeName[]")(i) & "%' and user_id like '%" & Request.Form("employeeId[]")(i) & "%'" , con 
    do while not rs.BOF and not rs.EOF 
    Response.Write("<tr>") 
    Response.Write("<td>" & rs("NameFieldName") & "</td>") 
    Response.Write("<td><input type=""text"" id=""nickname""></td>") 
    Response.Write("<td>" & rs("IdFieldName") & "</td>") 
    Response.Write("<td><input type=""text"" id=""address""></td>") 
    Response.Write("</tr>") 
    rs.MoveNext 
    loop 
    rs.Close 
%> 

對不起,如果我的語法有點關閉。自從我使用Classic ASP以來,這已經很長時間了。 :)您必須將數據庫字段名稱更改爲真實姓名,並且我不確定您在輸入字段中究竟是在尋找什麼,請相應地進行調整,但這應該足以讓您繼續。