Avoid Using Refresh() Method

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:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as