Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display data in ASP

Status
Not open for further replies.

axmug

Programmer
Oct 13, 2003
34
ES
Hi,

I want to display data from a database using ASP but I can't. I have a recordset with a connection in a database but appears me the following error in the browser:

The page cannot be displayed.

Bad arguments number or bad assignement property.

The code is:

<%

dim cnn
dim str
dim rs
dim rq

Set cnn=CreateObject("ADODB.Connection")
str="Data Source=INVENT;"
cnn.ConnectionString=str

cnn.Open str

Set rs=Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection=cnn
rq="select * from material"
rs.open rq

while not rs.EOF
rs("Nom") 'The error is in this line

rs.movenext
wend
cnn.Close

%>

The connection to the database is correct. The problem is the recordset and I don't know where the error is.

I would like to know why I can't display data.

Thanks.
 
Yes!!! It works now.

Thanks for the response.


 
Hi,

One more question. I'm trying to make a link but I can't. The idea is when you mark using mouse the link appears the id number of the name. For example:

Response.write "<a href="rs("num")">"rs("Nom")"

I point with the mouse above the link and I see the Nom ID number.

How can I do it? It appears the following error in my browser:

Final instruction missing

Thanks.
 
Try this:

Response.write "<a href="rs("num")">"rs("Nom")"</a>"

-DNG
 
actually its

Response.write "<a href=""" & rs("num") & """>" & rs("Nom") & "</a>"
 
Single quotes contained in a string are translated to double quotes when writing to the response buffer.

So this:

Response.write "<a href='" & rs("num") & "'>" & rs("Nom") & "</a>"

or this:

Response.write "<a href=""" & rs("num") & """>" & rs("Nom") & "</a>"

will output the same results.

-a6m1n0

"Don't try to reinvent the wheel." -My HS FORTRAN Professor
 
a6m1n0
single quotes in the string above will still be single quotes when they reach the browser. What makes you think they will change to double quotes?

Steven290
As far as I am aware, single quotes or double quotes are both perfectly valid in this example (as long as they are paired correctly of course). If this is incorrect then I would be interested to know.

Tony
_______________________________________________________________
 
Hi,

I just tested all the commands several people typed and the only one that didn't work is the first posted by DotNetGnat.

Thanks to everybody for the responses.

But the solutions typed here are not exactly what I want to do. The idea is when I click in the link I want appear another page with the content of the id that has the link.

In other words, what I want to do is to past parameters to an URL from one page to other.

That is, I have the information of a lot of computers and when I click in the link of one I want the information of that computer appears in another page.

I think ASP works like PHP. In PHP 4 (is the script language I know) the parameter you past to the other page is recognized in that page, but in ASP it seems no and it's not possible.

What I tested is the following code:

Response.write "<a href=siguiente.asp?" & rs("num") & ">" & rs("Nom") & "</a>"

When I click in this link I want to display the information of the computer with number rs("num") in the page siguiente.asp but appears me the following error instead:

Different types 'rs'

So I think the error is ASP doesn't recognize the recordset rs defined in the previous page. How can I solve this error?

Thanks.
 
axmug
In your intial post you stated:
rs("Nom") 'The error is in this line

When looking at your SQL statement, rq="select * from material", it is apparent that this is at least contributing to your problem.

Try:

rq="select field1, field2, field3 from material"

where field1, field2, and field3 are fields in your database. So if you had the fields id, product, description, price, you would format your SQL query like so:

rq="select id, product, description, price from material"

I think you get the idea. Although SELECT * 'works' in some cases, it is always better to specify the fieldnames in a SQL query.

FesterSXS
For some reason -- a misinformed one apparently -- I was under the impression that single quotes translated into double-quotes when written to the response buffer. After testing I stand corrected.

-a6m1n0

"Don't try to reinvent the wheel." -My HS FORTRAN Professor
 
The problem is not in the * in the query because I just tested typing all fields in the query and the error was the same as I posted in the fourth post.

I didn't find the solution yet.

Anyone knows how to solve it?

Thanks.
 
if it try this dsn-less getrows method

replace yourdb.mdb with your foldername/dbname

verify that the field name is nom not num

<%


strDBPath = Server.MapPath("yourdb.mdb")


Set conn= Server.CreateObject("ADODB.Connection")

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & ";"

Set rs = conn.Execute("SELECT nom FROM material")


rows = rs.GetRows()

rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing


RFirst = LBound(rows, 2)
RLast = UBound(rows, 2)


For I = RFirst To RLast

Response.Write rows(0, I) & vbCrLf

Next
%>
 
No, the database is SQL Server. But I don't think the problem is in the database. I think the problem is in the possibilities offers ASP.

My problem is simple: I want to pass a record number to another page and this number will be determined by the user's click. The problem is how to have stored the number when the user has clicked over the link he choose.

For example: a new's site. You have in a page the news titles and when you click over a title you can display in other page the whole new. To get to display the whole new it's necessary to pass an id new to determine in the other page which new has to be displayed.

What I don't know is, according to the example, how to preserve the id new to be displayed in the other page.

Thanks.
 
we coould try this

<%


Set conn= Server.CreateObject("ADODB.Connection")

conn.Open "PROVIDER=SQLOLEDB;DATA SOURCE=INVENT;UID=username;PWD=password;DATABASE=databasename;"

Set rs = conn.Execute("SELECT newsid,title FROM material")


rows = rs.GetRows()

rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing


RFirst = LBound(rows, 2)
RLast = UBound(rows, 2)


For I = RFirst To RLast

Response.Write "<a href=""newsdetails.asp?id="&rows(0, I) & """>"&rows(1, I)&"</a><br>"&vbCrLf

Next
%>
 
Steven,

I just typed the code and works but now I want to send rows(0,I) value to the page that opens when I click in a link.

How can I do it?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top