Wrox Programmer Forums
|
BOOK: VBScript Programmer's Reference, 1st, 2nd, and 3rd editions
This is the forum to discuss the Wrox book VBScript Programmer's Reference, 3rd Edition by Adrian Kingsley-Hughes, Kathie Kingsley-Hughes, Daniel Read; ISBN: 9780470168080
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: VBScript Programmer's Reference, 1st, 2nd, and 3rd editions section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 12th, 2004, 03:59 PM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO Command Object with Parameters

Does anyone have sample code showing how to create and use parameters with the creation and use of the ADO Command Object? I need to pass a parameter or two with my SQL statement. In the book on page 445 it says “We won’t cover parameters here.” It’s not covered anyplace else either.

 
Old March 13th, 2004, 05:04 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Let's say you have a stored procedure in SQL Server, or saved query in Access called "stp_GetAuthorsBySurname" which accepts a parameter called "Surname" which is a unicode string up to a length of 100. You will need to include the various constants needed for ADO, either by referencing adovbs.inc or defing the constants yourself. Your open connection is called oConn
Code:
Dim oCommand
Set oCommand = CreateObject("Adodb.Command")
Set oCommand.ActiveConnection = oConn
oCommand.CommandText = "stp_GetAuthorsBySurname"
oCommand.CommandType = adCmdStoredProc
Dim oParam
Set prmByRoyalty = CreateObject("ADODB.Parameter")
oParam.Type = adVarWChar
oParam.Size = 100
oParam.Direction = adParamInput
oParam.Value = "F%"
oCommand.Parameters.Append oParam
You are now ready to open a recordset with the command.

A good reference is
http://msdn.microsoft.com/library/de...asp?frame=true



--

Joe
 
Old March 15th, 2004, 03:52 PM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by joefawcett
 Let's say you have a stored procedure in SQL Server, or saved query in Access called "stp_GetAuthorsBySurname" which accepts a parameter called "Surname" which is a unicode string up to a length of 100. You will need to include the various constants needed for ADO, either by referencing adovbs.inc or defing the constants yourself. Your open connection is called oConn
Code:
Dim oCommand
Set oCommand = CreateObject("Adodb.Command")
Set oCommand.ActiveConnection = oConn
oCommand.CommandText = "stp_GetAuthorsBySurname"
oCommand.CommandType = adCmdStoredProc
Dim oParam
Set prmByRoyalty = CreateObject("ADODB.Parameter")
oParam.Type = adVarWChar
oParam.Size = 100
oParam.Direction = adParamInput
oParam.Value = "F%"
oCommand.Parameters.Append oParam
You are now ready to open a recordset with the command.

A good reference is
http://msdn.microsoft.com/library/de...asp?frame=true



--

Joe
 
Old March 15th, 2004, 03:54 PM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe,
Thanks for your help.
I got it to work!
Barbara







Similar Threads
Thread Thread Starter Forum Replies Last Post
Command text was not set for the command object Sheraz Khan Classic ASP Databases 2 May 29th, 2007 12:57 AM
Issues with Command Object and Parameters BSkelding Crystal Reports 0 May 2nd, 2007 10:29 AM
Syntax for OleDb Command Object Parameters aadz5 ASP.NET 1.0 and 1.1 Basics 4 November 20th, 2003 03:31 PM
trouble w/ command object and parameters RbH All Other Wrox Books 0 August 5th, 2003 12:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.