查找记录集中的特定元素,经典ASP

查找记录集中的特定元素,经典ASP

问题描述:

我试图从“选择”语句中提取特定元素以便填写网站上的表格。我将使用经典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 –

你只需要遍历记录,拿出你的任何字段值兴趣,并与相应的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以来,这已经很长时间了。 :)您必须将数据库字段名称更改为真实姓名,并且我不确定您在输入字段中究竟是在寻找什么,请相应地进行调整,但这应该足以让您继续。