Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Pro VB 6
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 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 January 17th, 2006, 08:37 PM
Authorized User
 
Join Date: Aug 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default Prepared SQL VS. Regular Queries

Guys,

I tried posting this topic in the VBA forum, but got no response. Perhaps someone from this forum can shine some light on this problem.

I tried to write a prepared sql script instead of just executing queries inside of a loop. I timed it, and the prepared script runs over a minute slower than the regular script. I don't understand why it would take longer. I was expecting to save some time.

Here is the prepared statement script:

Dim con As New ADODB.Connection
Dim com As New ADODB.Command
Dim strqry As String

con.ConnectionString = CurrentProject.Connection
con.CursorLocation = adUseServer
con.Mode = adModeReadWrite
con.Open

Dim rsData As ADODB.Recordset
Set rsData = New ADODB.Recordset
rsData.ActiveConnection = CurrentProject.Connection
rsData.CursorType = adOpenKeyset

strqry = " select q33_1 from test "
         rsData.Open (strqry)

Dim SQL_TO_USE As String
SQL_TO_USE = "update test set zip = 'TestThisString' where q33_1 = ?"

com.CommandType = adCmdText
com.Prepared = True
com.CommandText = SQL_TO_USE
com.Parameters.Append com.CreateParameter("value", adVarChar, adParamInput, 50)
Set com.ActiveConnection = con

While Not rsData.EOF
   com("value") = rsData("q33_1")
   com.Execute
   rsData.MoveNext
Wend

con.Close


Here is the regular way of doing it:

Dim strqry As String
Dim rsData As ADODB.Recordset
Set rsData = New ADODB.Recordset
rsData.ActiveConnection = CurrentProject.Connection
rsData.CursorType = adOpenKeyset

strqry = " select q33_1 from test "
         rsData.Open (strqry)

Dim rsAction As ADODB.Recordset
Set rsAction = New ADODB.Recordset
rsAction.ActiveConnection = CurrentProject.Connection

While Not rsData.EOF
   strqry = "update test set zip = 'RegularTest' where q33_1 = " & rsData("q33_1") & ""
   rsAction.Open (strqry)

   rsData.MoveNext
Wend

Any suggestions would be greatly appreciated.

nikotromus

nikotromus
__________________
nikotromus





Similar Threads
Thread Thread Starter Forum Replies Last Post
Prepared SQL VS. Regular Queries nikotromus Beginning VB 6 1 June 24th, 2006 10:08 AM
Prepared SQL VS. Regular Queries nikotromus Pro VB Databases 0 January 17th, 2006 08:35 PM
Prepared SQL VS. Regular Queries nikotromus Access VBA 2 January 14th, 2006 06:56 PM
Anyone Expert in SQL Queries? itHighway HTML Code Clinic 3 June 3rd, 2005 09:57 AM
Anyone Expert in SQL Queries itHighway Classic ASP Basics 2 May 24th, 2005 03:37 AM





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