Groups | Blog | Home
all groups > inetserver asp components > june 2005 >

inetserver asp components : Prepared statements in ASP


Bob Barrows [MVP]
6/3/2005 3:53:37 PM
[quoted text, click to view]
http://www.aspfaq.com/show.asp?id=2112

You may be interested in my command object code generator available here
(it's free):

http://www.thrasherwebdesign.com/index.asp?pi=links&hp=links.asp&c=&a=clear

If your procedure has no output parameters, and you aren't interested in
reading the Return parameter, then you don't need an explicit command
object. See http://tinyurl.com/jyy0

Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Bob Barrows [MVP]
6/3/2005 4:53:24 PM
[quoted text, click to view]

I suggest creating a simple asp page with the following two lines of code:

<%
set cn=createobject("adodb.connection")
response.write cn.Version
%>

Alternatively, you can #include the adovbs.inc file, but as Aaron's article
states, that file has many more constants than you will likely need.

[quoted text, click to view]

I thought you were talking about a stored procedure. I think this is what
you are asking about:
http://groups-beta.google.com/group/microsoft.public.inetserver.asp.db/msg/72e36562fee7804e

You don't need to build the parameters collection.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Bob Barrows [MVP]
6/3/2005 6:51:42 PM
[quoted text, click to view]

You already had an array. Why create a new one?

My normal practice is to be explicit about my datatypes. Is whereid numeric?
If so, explicitly convert it to the appropriate numeric subtype. Assuming
int:

params = array(updatedFirstName, updatedSurName, _
clng(whereId))

peopleUpdate.Execute , params, _
adExecuteNoRecords + adCmdText



[quoted text, click to view]
This is usually a warning. The update should have occurred. You should
probably use Left() to make sure the string you send to this statement is
not too long for the field into which it is going to be put.

You should be using the sqloledb OLE DB provider instead of the ODBC driver:
http://www.aspfaq.com/show.asp?id=2126


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

No one
6/3/2005 7:25:46 PM
I am trying to create a prepared statement in ASP, but am having
problems with creating the parameter object. I do the following

Set fnParam = peopleUpdate.CreateParameter("@firstname", adVarChar,
adParamInput, 50, peopleSourceRS("firstname"))

But this gives the following error on the browser:

Error Type:
ADODB.Command (0x800A0BB9)
Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.

The server doesn't seem to like adVarChar and adParamInput. I did try
to create the parameter without arguments and then assign the
properties, but it gives the same error for .Type and .Direction. What
am I doing incorrectly here?

No one
6/3/2005 8:41:35 PM
[quoted text, click to view]

Ugh....how do I know which MDAC I have?

[quoted text, click to view]

All I see here is how to call a stored procedure. I'm not calling a
stored proc, I want to make a prepared statement. Something like this:

UPDATE FOO_TABLE SET foName = @name, foPhone = @phone WHERE foId = @id

And then fill the parameters in at run time.

If I missed something on the page, please let me know.
No one
6/3/2005 9:27:33 PM
[quoted text, click to view]

I guess ODBC for MS SQL server doesn't support named parameters under
No one
6/3/2005 9:37:04 PM
[quoted text, click to view]

I changed the SQL to use this instead of the named params:

peopleUpdateSQL = "UPDATE People SET FirstName = ?, surname = ? WHERE id
= ?"


I create an array of my values like so:

updatedFirstName = peopleSourceRS("firstname")
updatedSurName = peopleSourceRS("surname")
whereId = peopleSourceRS("id")

Dim params
params = array(updatedFirstName, updatedSurName, whereId)

and I execute like so:

peopleUpdate.Execute , array(updatedFirstName, updatedSurName, whereId),
adExecuteNoRecords

I get this error on the browser:

Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E57)
[Microsoft][ODBC SQL Server Driver]String data, right truncation
/RepLocator/ProcessPeopleFile.asp, line 113

------------------------------------------
No one
6/3/2005 10:41:48 PM
[quoted text, click to view]


I looked at this code, but it seems, for update at least, that the error
code trap is backwards. WHen the update happened fine, err contained a
AddThis Social Bookmark Button