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

Finding specific elements in a recordset, classic ASP

我正在尝试从 "select" 语句中提取特定元素,以便在网站上填写 table。我将使用经典 ASP。

例如,我的 select 语句在 returns 这些值下面;

姓名ID 亚历克斯 Alex123

现在,在我的网页上,我希望 table 看起来像这样,

姓名昵称ID地址 Alex "input field" Alex123 "input field"

在我的 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

您只需要遍历记录集,提取您感兴趣的任何字段值并使用适当的 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了。 :) 您必须将数据库字段名称更改为真实名称,而且我不确定您正在寻找输入字段的确切内容,因此请相应地进行调整,但这应该足以让您继续前进.