How can I use a drop-down list to display database content?

Source: Internet
Author: User

<%
Dim objDC, objRS

Set objDC = Server. CreateObject ("ADODB. Connection ")
ObjDC. ConnectionTimeout = 15
ObjDC. CommandTimeout = 30

'Create a database connection

ObjDC. open "DBQ =" & Server. mapPath ("database. mdb ") &"; Driver = {Microsoft Access Driver (*. mdb)}; DriverId = 25; MaxBufferSize = 8192; Threads = 20; "," username "," password"
'UseAccessDatabase

ObjDC. Open Application ("SQLConnString"), Application ("SQLUsername "),
Application ("SQLPassword ")

Set objRS = Server. CreateObject ("ADODB. Recordset ")

'Create and retrieve Record Sets

'Use forward cursor (0) And read-only mode (1) Open record set
'If the specifiedIdThe request is read.
If Len (Request. QueryString ("id") <> 0 Then
'AccordingIdRead the corresponding records
ObjRS. Open "select * from intelsdb WHERE id =" & Request. QueryString ("id"), objDC, 0, 1
'Show selected records
If Not objRS. EOF Then
ObjRS. MoveFirst
%>
<Table border = 2>
<Tr>
<Td> <B> ID </B> </td>
<Td> <B>Name</B> </td>
<Td> <B>Department</B> </td>
<Td> <B>Monthly sales</B> </td>
</Tr>
<Tr>
<Td ALIGN = "center"> <% = objRS. Fields ("id") %> </td>
<Td ALIGN = "left"> <% = objRS. Fields ("name") %> </td>
<Td ALIGN = "left"> <% = objRS. Fields ("department") %> </td>
<Td ALIGN = "right"> <% = objRS. Fields ("sales") %> </td>
</Tr>
</TABLE>
<%
End If
ObjRS. Close
End If

ObjRS. Open "intelsdb", objDC, 0, 1
'Read the record set cyclically and display the result
If Not objRS. EOF Then
ObjRS. MoveFirst
'The following table callsQueryStringLiIdContent
%>
<Form action = "./db_pulldown.asp" METHOD = "get">
<Select NAME = "id">
<OPTION> </OPTION>
<%
'Until the record set is read.
Do While Not objRS. EOF
'For each record, it is an employeeIdCreate a selection tag and set the corresponding value
%>
<Option value = "<% = objRS. Fields (" id ") %>"> <% = objRS. Fields ("name ")%> </OPTION>
<%
'Get next record
ObjRS. MoveNext
Loop
%>
</Select>
<INPUT type = "submit" value = "Submit">
</FORM>
<%
End If

'Close and clear
ObjRS. Close
Set objRS = Nothing
ObjDC. Close
Set objDC = Nothing
%>

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.