Tuesday, March 20, 2012

ASP + ADO + SQL 2005, new column [ORD ID]?

I'm developing some queries using ASP with a componente built in Visual basic 6.0 SP6, I get the data using ADO to a SQL 2005 (version 9.0.1406) when I run a code like this:

Code Snippet

Sub ShowRs(rsAuxi)
Dim Campo
Response.Write "

"
Response.Write " Ord ID"
For Each Campo In rsAuxi.Fields
Response.Write " " & Campo.Name & ""
Next
Response.Write ""
Do While Not rsAuxi.EOF
Response.Write " "
Response.Write " " & rsAuxi.Absoluteposition & ""
For Each Campo In rsAuxi.Fields
Response.Write " " & Campo.Value & ""
Next
rsAuxi.MoveNext
Response.Write ""
loop
Response.Write "

"
end sub

the ADO execute a Store Procedure like this:

Code Snippet

CREATE PROCEDURE [dbo].[SP_TPO_REQ_HEAD]
AS
SET NOCOUNT ON
BEGIN
SELECT
[COD_REQ_HEADER],
[NUM_REQ_HEADER],
[FECHA]
FROM [dbo].[TPO_REQ_HEADER]
END

I supose that when I draw the ADO recordset in the ASP (using the frist code) I get a table with 3 columns, but I get a table with 4 fields!!! and the first column is ORDER ID, now my question is WHO IS ADDING THIS NEW COLUMN?

Thanks in advance

JJ

You must have been executing another procedure than the one mentioned above. Another attribute is not just added automagically.

Jens K. Suessmeyer

http://www.sqlserver2005.de

|||

The problem is your own code, which is adding the "new colunm":

' Your code, commented

Sub ShowRs(rsAuxi)

Dim Campo

Response.Write "<table border=1><tbody><tr>"

' This adds the Heading for the Ord ID "field"

Response.Write "<td class=TipoLetra>Ord ID</td>"

' This adds the heading for the fields returned in the Stored Procedure / in your example, 3 fields

For Each Campo In rsAuxi.Fields

Response.Write "<td class=TipoLetra>" & Campo.Name & "</td>"

Next

Response.Write "</tr>"

' This iterates as many records as your recordset (returned from stored procedure)

Do While Not rsAuxi.EOF

Response.Write "<tr>"

' THIS ADDS THE "FIELD", which is just the record number in the recordset !

Response.Write "<td class=TipoLetra>" & rsAuxi.Absoluteposition & "</td>"

' This iterates as many fields in each record, as returned in the recordset (3 in your example)

For Each Campo In rsAuxi.Fields

Response.Write "<td class=TipoLetra>" & Campo.Value & "</td>"

Next

rsAuxi.MoveNext

Response.Write "</tr>"

loop

Response.Write "</tbody></table>"

end sub

|||

thanks... I guess that I need a long vacations...

No comments:

Post a Comment