Re: Help with command object parameters query?

From: What-a-Tool (SeanMc_at_IHateSpam.Com)
Date: 03/27/05


Date: Sun, 27 Mar 2005 05:46:21 -0500


> No. Delimiters are not needed when using parameters. Here is a repro
> showing the passing of all of these parameter types (this is tested code
> which ran without error for me):
>
> <%
> dim cn, cmd, arParms, sSQL, rs, sHTML
> sSQL="CREATE TABLE InsertTest (" & _
> "IntCol smallint," & _
> "BoolCol bit," & _
> "TextCol CHAR(15)," & _
> "DateCol datetime," & _
> "SngCol real)"
>
> set cn = CreateObject("ADODB.Connection")
>
> 'substitute your database in the following string
> cn.Open "provider=microsoft.jet.oledb.4.0;data source=" & _
> server.MapPath("db7.mdb")
>
> cn.Execute sSQL,,129
>
> sSQL= "INSERT INTO InsertTest(IntCol,BoolCol,TextCol," & _
> "DateCol,SngCol) VALUES (?,?,?,?,?)"
>
> arParms=array(25,true,"test",#2005-03-22#,1.25)
>
>
> set cmd=createobject("adodb.command")
> cmd.CommandText=sSQL
> set cmd.ActiveConnection=cn
> cmd.Execute ,arParms,129
> set cmd=nothing
>
> sSQL="select IntCol,BoolCol,TextCol," & _
> "DateCol,SngCol from InsertTest"
>
> set rs=cn.Execute(sSQL,,1)
> sHTML=rs.getstring(2,,"</td><td>","</td></tr><tr><td>")
> rs.close:set rs=nothing
> cn.Close:set cn=nothing
> Response.Write "<table border=""1""><tr><td>"
> Response.Write left(sHTML,len(sHTML)-8)
> Response.Write "</table>"
>
> %>
>
> BTW, you may be interested in going to the next level: saved parameter
> queries. The code is even easier to write than the Command object code.
> See:
> http://groups-beta.google.com/group/microsoft.public.inetserver.asp.db/msg/b3d322b882a604bd
>
> 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"

AhHa - I see my error - Delimeters are needed, but in the array itself. (and
I thought I tried everything - DOWH!)

Saved parameter query - Very interesting - Thanks for the help and the tips

Sean


Loading