querying SQL in ASP?

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
Cna somebody provide a simple connection string/query example to use in an .asp webpage that will display the results of the query?

I just need some "jumping off point" of how to get this started so I can start to play with a working example, and I'm struggling with that.

I THINK I have a working connection string in the following:

<%
dim con, Rs
set con=server.CreateObject("adodb.connection")
con.Open "Provider=sqloledb;SERVER=SQL;DATABASE=CLS;UID=<Uid>;PWD=<UidPass>;"


Sql = “SELECT FILENO FROM MASTER WHERE FORW_NO =’1234’”

Dim Adapter as SqlDataAdapter = New SqlDataAdapter(SQL,cn)

Rs = New DataSet
Adapter.fill(rs,”master”)
Cn.close()
%>


Any help would be appreciated.
Thanks in advance.
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
This part is ASP.Net not ASP

Code:
Dim Adapter as SqlDataAdapter = New SqlDataAdapter(SQL,cn)

Rs = New DataSet
Adapter.fill(rs,&#8221;master&#8221;)

Heres an ASP sample:

Code:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Provider=sqloledb;Data Source=SQLSERVERNAME;Initial Catalog=DATABASENAME;User Id=myUsername;Password=myPassword;

set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn

for each x in rs.fields
  response.write(x.name)
  response.write(" = ")
  response.write(x.value)
next
%>

Here's a nice tutorial on ADO

http://www.w3schools.com/ado/default.asp
 

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
Yeah I guess I was mixing and matching languages then. Thanks for explaining.

I tried the example you gave (and subsequently looked at the examples in the tutorial you linked) but I still get an error when going to my page:

Server Error

500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.


I obviously updated with the correct server/table/user/passwords.
 

Homerboy

Lifer
Mar 1, 2000
30,890
5,001
126
Connection string should be:

conn.Open "Driver= {SQL Server Native Client 10.0};Server=SQL;Database=CLS;Uid=USERNAME;Pwd=PASSWORD"