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.
 
it should be sending it a querystring

look closely

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

I know with this code I can send the value rows(0,I) to the other page but once in this other page I want to make a query like "select num, nom from material where num = row (0,I)".

I typed the following code:

dim cn

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

conn.Open "DATA SOURCE=INVENT;"

Set rs = conn.Execute("SELECT num,nom FROM material where num=rows(0,I)")

I have this lines in the other page that isn't the same where I have the previous code I posted above. And in this other page I want to display the information about the new specified in rows(0,I).

I can't display the information because it appears me the following error:

rows(0,I) Unknown object.

How can I solve it?

Thanks.
 
The value you are after is not submitted to the page in the array. The array value is added to the querystring value id. It is this querystring value that you need to extract on your page.
Code:
Set rs = conn.Execute("SELECT num,nom FROM material where num=" & CInt(Request.QueryString("id")) & ";")

Tony
_______________________________________________________________
 
ax,
fester is correct you call it using request.querystring("id) or request("id")

but i would stick to the dsn-less connection + getrows just so it becomes a habit.

<%
strid=request.querystring("id")


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

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

Set rs = conn.Execute(SELECT num,nom FROM material where num="&strid&")

if not rs.eof then
strnum=rs(“num”)
strnom=rs(“nom”)
else
norecords=true
end if

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


 
If [red]Request.QueryString("id")[/red] is a number then you will need to convert it to an integer before using it in your SQL string (see my previous post in this thread) otherwise it might be treated as a String and cause a type mismatch error.

Tony
_______________________________________________________________
 
i've never had to (god knows i've done it alot), but if you like it wouldn't hurt
 
Hi,

What FesterSXS posted works. But I have some names with blanks in the database and when I type Request.QueryString("nom") I display in the screen all characters before blank.

What I want to do is to display the whole name and I don't know how to do it (I know one way: to delete all blanks in the name but it's difficult because I have approximately one thousand records in the database).

Here is the code:

dim conn
dim RFirst
dim RLast
dim rs
dim I

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

conn.Open "DATA SOURCE=INVENT;"

Set rs = conn.Execute("SELECT num,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 "<a href=siguiente.asp?id=" & rows(0,I) & "&n=" & rows(1,I) & ">" & rows(1,I) & "</a><br>"

Next

In the rows(1,I) array I have the name cut until the first blank.

How can I resolve it?

Thanks.
 
You need quotes around your href string...
Code:
Response.write "<a href=[red]""[/red]siguiente.asp?id=" & rows(0,I) & "&n=" & rows(1,I) & "[red]""[/red]>" & rows(1,I) & "</a><br>"

Tony
_______________________________________________________________
 
I have the problem resolved. Thank you to everybody for responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top