[quoted text, click to view] michael sorens wrote:
> It took some digging through your posts and from there to some other
> material before I was able to cobble a working example together.
>
> I went from this:
>
========================================================================
==
[quoted text, click to view] > sqlS1 = "SELECT SiteName FROM Sites S WHERE IDSite=" & S1
> set rsS1 = server.CreateObject("ADODB.Recordset")
> rsS1.Open sqlS1, WebconnectString, adOpenStatic, ,adCmdText
> Site = rsS1("SiteName")
>
========================================================================
==
[quoted text, click to view] >
> To this (looks good with a fixed width font:-):
>
========================================================================
==
[quoted text, click to view] > sqlS1 = "SELECT SiteName FROM Sites S WHERE
> IDSite=?" arParams = array(S1)
> set cmd = createobject("ADODB.Command")
> cmd.CommandText = sqlS1
> set cmd.ActiveConnection = myConn
> set rsS1 = cmd.Execute(,arParams)
> Site = rsS1("SiteName")
>
========================================================================
==
[quoted text, click to view] >
> ...resulting in the same Site name in both cases.
>
> Is my revised code above the proper way to do it? You actually did
> not have any examples in the reference posts you provided that showed
> queries returning data; they were all for INSERT statements.
Yes, that's it. I would add the CommandType statement:
cmd.CommandType = 1 'adCmdText
99 times out of a hundred, this will suffice for asp. For the rare
occasions when you need a different cursor type from the default
firehose cursor (perhaps a clientside static cursor), you need to build
the Parameters collection and use the recordset's Open method to open
it:
sqlS1 = "SELECT SiteName FROM Sites S WHERE IDSite=?"
set cmd = createobject("ADODB.Command")
cmd.CommandText = sqlS1
cmd.CommandType = 1 'adCmdText
Const adInteger = 3
Const adParamInput = &H0001
Const adUseClient = 3
cmd.Parameters.Append cmd.CreateParameter("SiteID", _
adInteger, adParamInput,,S1)
Set rs=CreateObject("adodb.recordset")
rs.CursorLocation=adUseClient
rs.Open cmd
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.