Article ID: 186276
Article Last Modified on 3/2/2005
UPDATE tblBatchUpdate SET fldValue=? WHERE ID=? AND fldValue=?;Note that there are three parameters that give the number of parameters in the batch when multiplied by the BatchSize property value. If this number exceeds the parameter limit of 500, you will get the error "Invalid Parameter Number."
Option Explicit
Dim Cn As New rdoConnection
Dim Rs As rdoResultset
Private Sub Form_Load()
EstablishConnection
Command1.Caption = "Create Table"
Command2.Caption = "Fill Table"
Command3.Caption = "Batch Update"
Command2.Enabled = False
Command3.Enabled = False
End Sub
Private Sub Command1_Click()
Dim strCreateTable As String
Dim Response As Integer
strCreateTable = "CREATE TABLE dbo.tblBatchUpdate (" _
& "ID int IDENTITY (1, 1) NOT NULL PRIMARY KEY," _
& "fldValue int NULL)"
Debug.Print strCreateTable
If Not Cn.rdoTables("tblBatchUpdate").Updatable Then
'table exists
Response = MsgBox("Table exists" & vbCrLf & _
"Do you what to delete it?", vbYesNo)
End If
If Response = vbYes Then
Cn.Execute ("Drop table tblBatchUpdate")
Debug.Print "Creating new table..."
Cn.Execute strCreateTable
End If
Command2.Enabled = True
Command3.Enabled = True
End Sub
Private Sub Command2_Click()
Dim i As Integer
Dim strSQLInsert As String
MousePointer = vbHourglass
For i = 1 To 200
strSQLInsert = "INSERT tblbatchupdate (fldValue) " _
& "VALUES (" & i & ")"
Cn.Execute (strSQLInsert)
Next i
MousePointer = vbNormal
End Sub
Private Sub Command3_Click()
RefreshRS
MousePointer = vbHourglass
If Rs.RowCount > 0 Then
Rs.MoveFirst
Do While Not Rs.EOF
Rs.Edit
Rs(1) = Rs(1) + 1
Rs.Update
Rs.MoveNext
Loop
Rs.BatchUpdate
End If
MousePointer = vbNormal
End Sub
Private Sub EstablishConnection()
With Cn
.Connect = "UID=<username>; PWD=<strong password>; Database=pubs;" _
& "Server=MySQLServer;Driver={SQL Server}"
.CursorDriver = rdUseClientBatch
.EstablishConnection rdDriverNoPrompt, False
Debug.Print Cn.Connect
End With
End Sub
Private Sub RefreshRS()
Dim Sql As String
Dim rdoQuery1 As rdoQuery
Sql = "SELECT ID, fldValue FROM tblbatchupdate;"
Set rdoQuery1 = Cn.CreateQuery("sql", Sql)
rdoQuery1.RowsetSize = 1000
Set Rs = rdoQuery1.OpenResultset( _
Type:=rdOpenKeyset, LockType:=rdConcurBatch)
Rs.rdoColumns(0).KeyColumn = True
Rs.BatchSize = 167 'Value of 166 works and 167 fails
'Reason - 166 * 3 = 497 -Works and
'167 * 3 = 501 - Fails
'Because - this is the update statement sent out -
'"UPDATE tblbatchupdate SET fldValue=? WHERE ID=? AND fldValue=?;"
'Notice 3 parameters. No. of parameters * no. of rows cannot
'exceed 500.
'
Rs.UpdateCriteria = rdCriteriaUpdCols
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cn.Close
End Sub
Keywords: kbprb KB186276