Query a SQL database with ASP using a DSN-less connection

                                                        
1 <%
2 Dim cnnSimple ' ADO connection
3 Dim rstSimple ' ADO recordset
4 Set cnnSimple = Server.CreateObject("ADODB.Connection")
5 ' DSNLess
6 cnnSimple.Open "Provider=SQLOLEDB;Data Source=YOURDBSERVER;" _
7 & "Initial Catalog=YOURDBNAME;User Id=YOURUSERID;Password=YOURPASSWORD;" _
8 & "Connect Timeout=15;Network Library=dbmssocn;"
9 Set rstSimple = cnnSimple.Execute("SELECT * FROM tbltest")
10 %>
11 <P> Connecting to SQL DB with DSNless connection P>
12 <TABLE border=1><%
13 Do While Not rstSimple.EOF
14 %><TBODY><TR><TD><%= rstSimple.Fields("id").Value %>TD><TD>%&gt;= rstSimple.Fields("name").Value %&gt;TD>TR><%
15 rstSimple.MoveNext
16 Loop
17 %>TBODY>TABLE>
18 <%
19 rstSimple.Close
20 Set rstSimple = Nothing
21 cnnSimple.Close
22 Set cnnSimple = Nothing
23 %>
24
25

  • 0 用戶發現這個有用
這篇文章有幫助嗎?

相關文章

Sample Code on how to send email using Classic ASP

If you are using ASP to send email on our emailserver, please avoid using CDONTS. We no longer...

Redirect a subdomain to a subdirectory

You can redirect a subdomain to a subdirectory by using ASP or ASP.net code. When the...

Query MySQL database in ASP

1 2 3 <% 4 5 Dim cnnSimple ' ADO...