asp variables not displaying

R

Rahul Chatterjee

Hello All

I have an asp page in which I am performing the following

1. Querying a database view
2. Returning rows in to a recordset.
3. Looping thru the recordset and printing the data
4. Before displaying the data I am assigning the values from the recordset
into variables
5. There are 2 entry points to this page both of which would run similar
queries and return similar results

My problem is that for a certain sequence of variable assignments, my data
is not displaying on the screen (even though when i do a response.write I
see that the variable actually has a value in it). In order to fix it I
rearranged the sequence of assignments but since I have two entry points to
the page, it didnot display the data for the other entry point

Can anyone help with a suggestion/solution

Thank you
 
T

Tom B

Perhap if you showed your code, we could make a suggestion, as it is it's a
little difficult to guess what the problem is.
 
R

Rahul Chatterjee

Here it is. This query is populated by a select * from tablename query.
All vars return values when we do response.write to see but does not
display when just output plainly.

Please advise

if not rsDetails.eof then
rsDetails.movefirst
prevProjectID = rsDetails("ProjectID")
do while not rsDetails.eof

ProjectID = rsDetails("ProjectID")
WorkDt = rsDetails("WorkDt")
EstHrs = cint(rsDetails("EstHrs"))
Hours = rsDetails("Hours")
Details = rsDetails("Details")
Initials = rsDetails("Initials")
Billed = rsDetails("Billed")

if prevProjectID = ProjectID then%>
<tr>
<td valign="top" align="center" width="114"><%=ProjectID%></td>
<td valign="top" width="26"><%=WorkDt%></td>
<td valign="top" align="center" width="65"><%=Initials%></td>
<td valign="top" align="center" width="66"><%=EstHrs%></td>
<%hrAccum = hrAccum + Hours%>
<td valign="top" width="22"><%=Hours%></td>
<%HrDiff = EstHrs - Hours%>
<td valign="top" align="center" width="66"><b><%=HrDiff%></b></td>

<%Details = replace(Details, "&quot;", "'")%>
<td valign="top" width="300"><%=Details%></td>


<%if Billed <> "" then
if Billed = 1 then%>
<td valign="top" align="center" width="34">Y</td>
<%else%>
<td valign="top" align="center" width="12">N</td>
<%end if%>
<%else%>
<td valign="top" align="center" width="12">N</td>
<%end if%>
</tr>
 
R

Ray at

Do you see them in a view source? It sounds like it's an HTML problem.
Like, you're saying you WOULD see the value if:

<%

response.write ProjectID

%>

but you don't see it in :
<td valign="top" align="center" width="114"><%=ProjectID%></td>

?

What's in the html source?

Ray at work
 
T

Tom B

I assume that you have
1) rsDetails.MoveNext and Loop somewhere
2) a table opening tag

Does it send anything? If you view source do you see anything?
As you have "everything" within the
If prevProjectID=ProjectID
structure, do you close it somewhere(end if) , do you set prevProjectID
somewhere? If not, then you'll only get the first ProjectID's information.
If that's what you want, you'd be better off rewriting your SQL Select
statement

I don't think there's any need to movefirst.


From the code you've shown, there doesn't appear to be anything wrong,
assuming that the rest of the page is right.
 
R

Ray at

Are you seeing everything but the values then, or perhaps you're not seeing
anything because your IF condition is never true. What happens if you put
something else in the td's with the variables so you can be sure that you're
seeing the table fully and everything.

---------------------
if prevProjectID = ProjectID then%>
<tr>
<td valign="top" align="center" width="114">Project ID = <%=ProjectID%></td>
<td valign="top" width="26">WorkDT = <%=WorkDt%></td>
<td valign="top" align="center" width="65">Initials =
<%=Initials%></td>
<td valign="top" align="center" width="66">EstHrs = <%=EstHrs%></td>
<%hrAccum = hrAccum + Hours%>
<td valign="top" width="22">Hours = <%=Hours%></td>
<%HrDiff = EstHrs - Hours%>
<td valign="top" align="center" width="66"><b>HrDiff = <%=HrDiff%></b></td>

<%Details = replace(Details, "&quot;", "'")%>
<td valign="top" width="300">Details = <%=Details%></td>


<%if Billed <> "" then
if Billed = 1 then%>
<td valign="top" align="center" width="34">Y</td>
<%else%>
<td valign="top" align="center" width="12"><B>ELSE CONDITION
EXECUTED</B> N</td>
<%end if%>
<%else%>
<td valign="top" align="center" width="12">N</td>
<%end if%>
</tr>
--------------------

Also, just for the hell of it, put Option Explicit in your page if it's not
already there.

Ray at work
 
O

only me

You don't mention which database is in use SQL server or Access - I suspect
the former

Having just ported a project across from Access to Sql Server (MSDE
actually), I have to say how suprised I was at the way recordset variables
would just disappear, or not be available shortly after having opened a
recordset.when using SQL server compared to Access/Jet

This article indicates the problem
http://www.aspfaq.com/show.asp?id=2188
but I 've also noticed it with date fields

my experience indicate that also the fields must be stored in to variables
in the exact order in which they were called in the select part of the sql -
of course very difficult when a * appears in the Select

You say your SQL is similar in both cases but not the same so I would think
almost certainly you need to store those vars in a different order for each
SQL

Access seesm to be much more forgiving ( by design?) in this respect, you
could open a record set at the top of a page and the recordset variables
would still be avaible by the time you got to the bottom ( except memo
fields on earlier version of MDAC as I recall) - (leaving a recordset open
that long is I, accept bad practice)

It does seem to be quite a large bug/feature of SQL server / MDAC - surely
its not by design ?

Maybe this is why GetRows gets pushed so highly round here and on the
various boards - yet to try it myself

just my 2p worth
 
B

Bob Barrows

only said:
You don't mention which database is in use SQL server or Access - I
suspect the former

Having just ported a project across from Access to Sql Server (MSDE
actually), I have to say how suprised I was at the way recordset
variables would just disappear, or not be available shortly after
having opened a recordset.when using SQL server compared to Access/Jet
I have NEVER encountered this problem. Even before I learned to start using
GetRows. Of course, I rarely use Text columns, but you seem to be saying
that it occurs for other dataypes as well ...

If you have a repro (SQL DDL, sample data, asp page) for this problem I
would love to play with it. I have never been able to reproduce this problem
when it has come up in these newsgroups.

Thanks,
Bob Barrows
 
J

jason kennedy

this may be a recordset cursor issue
i think it's because you're retrieving the ProjectID twice.
that won't work with certain recordset cursors.
it leads to exactly the error you're describing

Forward Only(0) - Means you can only move forwards through the recordset.
Keyset(1) - allows you to move forwards and backwards through the recordset.
It also allows you see changes to the recordset as the records are
identified by keys. As such it is the least efficient of the CursorTypes and
shouldn't really be used.
Dynamic(2) - allows you to move forwards or backwards through the recordset.
Any changes to the recordset will also be visible.
Static(3) - allows you move forwards or backwards through the recordset.
However, this cursortype takes a static snapshot of the records at the time
the recordset is created. So, any changes to the recordset will not be seen
until the recordset is recreated.

hope this helps,

Jason

Ray at said:
I'd like a copy too please. :]

Ray at home

Bob Barrows said:
I have NEVER encountered this problem. Even before I learned to start using
GetRows. Of course, I rarely use Text columns, but you seem to be saying
that it occurs for other dataypes as well ...

If you have a repro (SQL DDL, sample data, asp page) for this problem I
would love to play with it. I have never been able to reproduce this problem
when it has come up in these newsgroups.

Thanks,
Bob Barrows
 
J

jason kennedy

http://charon.co.uk/content.aspx?CategoryID=4&ArticleID=6

sorry, forgot to credit source. that article also mentions some SQLserver
scenarios that may throw similar errors to yours

jason


jason kennedy said:
this may be a recordset cursor issue
i think it's because you're retrieving the ProjectID twice.
that won't work with certain recordset cursors.
it leads to exactly the error you're describing

Forward Only(0) - Means you can only move forwards through the recordset.
Keyset(1) - allows you to move forwards and backwards through the recordset.
It also allows you see changes to the recordset as the records are
identified by keys. As such it is the least efficient of the CursorTypes and
shouldn't really be used.
Dynamic(2) - allows you to move forwards or backwards through the recordset.
Any changes to the recordset will also be visible.
Static(3) - allows you move forwards or backwards through the recordset.
However, this cursortype takes a static snapshot of the records at the time
the recordset is created. So, any changes to the recordset will not be seen
until the recordset is recreated.

hope this helps,

Jason

Ray at said:
I'd like a copy too please. :]

Ray at home

Bob Barrows said:
only me wrote:
You don't mention which database is in use SQL server or Access - I
suspect the former

Having just ported a project across from Access to Sql Server (MSDE
actually), I have to say how suprised I was at the way recordset
variables would just disappear, or not be available shortly after
having opened a recordset.when using SQL server compared to Access/Jet

I have NEVER encountered this problem. Even before I learned to start using
GetRows. Of course, I rarely use Text columns, but you seem to be saying
that it occurs for other dataypes as well ...

If you have a repro (SQL DDL, sample data, asp page) for this problem I
would love to play with it. I have never been able to reproduce this problem
when it has come up in these newsgroups.

Thanks,
Bob Barrows
 
O

only me

Would like to be able to assist with a sample guys, but this is quite a big
project and it would be a heck of a lot of work to strip it down to a basic
reproducible sample

But it IS a real problem (for me anyway), the biggest pain is the fact that
there is no error generated.
I have only suffered from "(a) not show up at all, (b) only show up the
first time they're called," (http://www.aspfaq.com/show.asp?id=2188)

The problem is definately compounded by the use of the * in the select - so
even if the table has only 3 fields its still better to list them
individually in the select, although that still won't be enough in the case
of memo fields ( not sure what the SQL upsizer converted those to at the
moment)

The ASPFAQ article doesn't indicate its limited to just one database type -
but our code has been running for about 2 years on Access without problem
( with rather to much use of the * in SELECT's it has to be said).
Have converted it to MSDE over the last 3 weeks, and had numerous instances
of fields not being picked up.
Using lastest MDAC - 2.8 I think

And yes I have seen it with what was an Access date/Time field -
rs("FullMemberUntil") in sample #2

Also as I said the order of storing the recordset variables is important -
seems it must follow the left to right order of how it would appear in
Access Table display

I think Rahul may need to have 2 differnet set of recordset to var
assignment statments to match each of his 2 SQL statements


samples
I have refered to the field types by their Access names, don't have access
to what the SQL upsizer converted them to at the moment

* #1 Despite specifically calling out all the fields used, had to resort to
For/Next to get ALL vars
* text_n ( Access memo fields) head_n and image_n (Access text fields)
*
dim fieldlist
fieldlist =
"PageTitle,EditorType,head_1,head_2,head_3,head_4,head_5,image_1,image_2,ima
ge_3,image_4,image_5,text_1,text_2,text_3,text_4,text_5"
sql = "SELECT " & fieldlist & " FROM [pages] WHERE CompanyID = " & CompanyID
& " AND PageNo= " & PageNo
set rs_pages = Conn.execute(sql)
if rs_pages.EOF then ' there is no page in database, so create an empty one
sharpish, and re enter at the top of the page
response.redirect "CreateBlankPage.asp?CompanyID=" & CompanyID & "&pageno="
& pageno
end if

for i = 1 to 5
textblock(i) = trim(rs_pages("text_" & i ) & " ")
headblock(i) = trim(rs_pages("head_" & i ) & " ")
imgcapblock(i) = trim(rs_pages("image_" & i ) & " ")
next
pagetitle = rs_pages("PageTitle")



* #2
* This line "if FullMemberUntil >= Now then" used to be "if
rs("FullMemberUntil") >= Now" - but had to be converted to what you see
below to work in MSDE
* "FullMemberUntil" is a Access dateTime field

sql = "SELECT Company.*, Locality.*, Countries.* "
sql = sql & "FROM Countries INNER JOIN (Locality INNER JOIN Company ON
Locality.LocalityID = Company.LocalityID) ON Countries.CountryID =
Locality.CountryID "
sql = sql & " WHERE CompanyID=" & CompanyID

Set rs = conn.Execute(sql)

' do not change the order of these statements
comments = trim(rs("comments") & "") #### a meno field from
company table
GMcustomerID = rs("GMcustomerID") #### a number field from company
FullMemberUntil = rs("FullMemberUntil") #### a date/time field from
company
county = rs("county") #### a text
field from Locality
region = rs("region") #### a text
field from Locality
countryname = rs("countryname") #### a text field from
Countries
' do not change the order of these statements


if FullMemberUntil >= Now then
IsFullMember = True
else
IsFullMember = false
end if


project : www.index.guestmaster.com



Ray at said:
I'd like a copy too please. :]

Ray at home

Bob Barrows said:
I have NEVER encountered this problem. Even before I learned to start using
GetRows. Of course, I rarely use Text columns, but you seem to be saying
that it occurs for other dataypes as well ...

If you have a repro (SQL DDL, sample data, asp page) for this problem I
would love to play with it. I have never been able to reproduce this problem
when it has come up in these newsgroups.

Thanks,
Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top