Query for a record, output by the field you select.

Source: Internet
Author: User
There are the following forms, you want to query a record, press the field output (field name fieldname1,fieldname2 ...). Please specify according to the field name in your table:
Input.htm
<form method= "Post" action= "test.asp" Name= "Form1" >
<input type= "text" name= "Bianhao" size= "ten" >
<input type= "checkbox" Name= "C1" value= "FieldName1" >
<input type= "checkbox" Name= "C1" value= "FieldName2" >
...
<input type= "Submit" value= "submitted" >
</form>
The corresponding ASP file as follows, this code is very versatile (database mymdb.mdb you specify, table name tablename you specify):
Test.asp
<%
Dim Fieldnames,fields
FieldNames = ""
' Traverse the form checkbox to save the selected field to a string variable filednames
For each fieldname in Request ("C1")
FieldNames = FieldNames & "," & FieldName
Next
' Determine if there are options
If FieldNames = "" Then
Response.Write "<center>Response.End
End If
' Connect the database, open the recordset RS
strSQL = "Select" & Mid (fieldnames,2) & "from TableName Where bianhao= '" & Request ("Bianhao") & ""
strconn = "Driver={microsoft Access DRIVER (*.mdb)};D bq=" & Server.MapPath ("Mymdb.mdb")
Set Rs = Server.CreateObject ("ADODB.") RecordSet ")
Rs.Open strsql,strconn,1,1
' Explode string variable filednames, output results by selected field
Fields = Split (FieldNames, ",")
For i = 1 to UBound (fields)
Response.Write Fields (i) & ":" & Rs (Fields (i)) & "<br>"
Next
Rs.close
%>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.