Avoid Using Refresh() Method

Refresh method of Parameters collection is used to populate the Parameter
objects in the collection. This method queries the data provider to
populate the collection with Parameter objects containing specific details
of the parameters. After execution of this method, you can access this
collection to stuff in the values of the parameters or to check other
properties of parameters.

You should avoid the usage of this method because it makes a hit to the
server to get the parameter details. If you are using SQL Server, you can
always run SQL Trace utility to verify that a call to Refresh makes a hit
to the server to get the parameters. But during development stage, you can
always use this method to know the exact details about the parameters and
later on you can use CreateParameter() method of Command object to populate
the Parameters collection using code.

Here is a sample method which uses both Refresh and CreateParamter() to
build the parameter information for the stored procedure:

 Private Sub BuildParameterInfo(ByVal lngSampleIdNo As Long, 
strSampleName As String, strSampleDesc As String)Dim oConnection As ADODB.Connection ' Connection ObjectDim oCommand As ADODB.Command ' Command Object' Create a new Connection ObjectSet oConnection = New ADODB.Connection' Create a new Command ObjectSet oCommand = New ADODB.Command' Open the connectionoConnection.Open "DSN=Sample", "sa", ""' Set connection into the Command ObjectSet oCommand.ActiveConnection = oConnection' Set Command text property to the name of stored procedure to be
executedoCommand.CommandText = "sp_AddRecordToSampleTable"oCommand.CommandType = adCmdStoredProc' ** ** Quick but Expensive way to build the parameter information by
calling refresh methodWith oCommand.Parameters.Refresh.Item(1).Value = lngSampleIdNo.Item(2).Value = strSampleName.Item(3).Value = strSampleDescEnd With' ** ** Efficient way to build parameter information by calling
CreateParameter() method and then' ** ** appending it to the Parameters collectionWith oCommand.Parameters.Append oCommand.CreateParameter("SampleIdNo", adInteger, adParamInput,, lngSampleIdNo).Append oCommand.CreateParameter("SampleName", adVarChar, adParamInput,20, strSampleName).Append oCommand.CreateParameter("SampleDesc", adVarChar, adParamInput,200, strSampleDesc)End With' Call Execute of Command Object to execute the stored procedureoCommand.ExecuteEnd Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may