Re: problem with ("ADODB.RecordSet")



Wendy Elizabeth (WendyElizabeth@xxxxxxxxxxxxxxxxxxxxxxxxx) writes:
> I am working with the following code:
>
> Set Conn=Server.CreateObject("ADODB.Connection")
> Set rs=Server.CreateObject("ADODB.RecordSet")
> Conn.Open CU_DSN
> rs.Open "SELECT * FROM tbl_AddrChange WHERE ID=" & szID & " AND
>
> CUNumber=" & CheckString(Session("CUNumber"),""),Conn
>
> FUNCTION CheckString (s, endchar)
> pos = InStr(s, "'")
> While pos > 0
> s = Mid(s, 1, pos) & "'" & Mid(s, pos + 1)
> pos = InStr(pos + 2, s, "'")
> Wend
> CheckString="'" & s & "'" & endchar
> END FUNCTION
>
> The following line of code is having a problem:
> "rs.Open "SELECT * FROM tbl_AddrChange WHERE ID=" & szID & " AND
> CUNumber=" & CheckString(Session("CUNumber"),""),Conn"
>
> This is code is for a server program that uses classic asp (vbscript). A
> sql server 2000 databaase is used in the applcation. The above line of
> code does select the correct row in the sql server 2000 table and all
> the columns are selected. However, all the values from the table is not
> selected. A few columns obtain their values but the rest of the columns
> from the sql server 2000 table are not obtained. I have been trying to
> solve this problem for awhile. Thus, can you tell me what could cause
> some rows to not be selected.

I have a little problem to understand what your problem actually
is, because the paragraph above appears to be contradictive.

However, using SELECT * in programming code is not good practice. It's
better to list the column you are actually using. This makes it easier
to find out whether a certain column is in use. Also, if the table
is wide, and you only use a handful of columns, bringing over
all columns is a waste of network bandwidth,

I would also recommend that you use parameterized SQL statements, rather
than building strings on the fly. There are both security and performance
benefits with this.

In such case you would use the Command object, and the actual command would
look like this:

SELECT col1, col2 FROM tbl_AddrChange
WHERE ID = ? AND CUNumber = ?

The ? are placeholders for the parameters.

Then you add the parameters with .AddParameter.

--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
.



Relevant Pages

  • vbscript ADODB.RecordSet not returning all values selected
    ... FUNCTION CheckString (s, endchar) ... select the correct row in the sql server 2000 table and all the columns are ...
    (microsoft.public.scripting.vbscript)
  • problem with ("ADODB.RecordSet")
    ... FUNCTION CheckString (s, endchar) ... select the correct row in the sql server 2000 table and all the columns are ...
    (microsoft.public.data.oledb)
  • ("ADODB.RecordSet") access problem
    ... FUNCTION CheckString (s, endchar) ... A sql server 2000 databaase is used in the applcation. ... of code does select the correct row in the sql server 2000 table and ...
    (microsoft.public.sqlserver.odbc)
  • Re: Is 40,000 rows too much for xml output from ado.net?
    ... using the ado.net command object. ... into memory tables (dataTables). ... writing that data to Sql Server. ... >As you have discovered we are missing proper bulk update ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Stored Procedure call and passing parameters
    ... I would like to use the ado command object to pass parameters to a stored ... procedure in a MS2000 SQL server. ... I need to do some modification and was wondering if Excel would support and ...
    (microsoft.public.excel.programming)