Solved

Locktype with Command-object

Posted on 2000-02-16
11
409 Views
Last Modified: 2013-12-25
Hi,

I´m using a the Execute-method of the Command-object to call a stored procedure that returns a couple of parameters and a recordset. The problem is that the recordset is set to adLockReadOnly and can´t be updated. Is it only possible to set Locktype using the open-method of the Recordset or what?
I want to use a disconnected recordset and modify it on the client and then update the database(SQL7) with updatebatch.

0
Comment
Question by:polksolk
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 1

Expert Comment

by:mmips
Comment Utility
Yes...Follw the following example from MS

' Open employee table.
   Set rstEmployees = New ADODB.Recordset
   rstEmployees.CursorType = adOpenKeyset
   rstEmployees.LockType = adLockOptimistic
   rstEmployees.Open "employee", cnn1, , , adCmdTable
0
 
LVL 1

Expert Comment

by:mmips
Comment Utility
To make it a disconnected recordset set the connection object cursor type to aduseclient. Then after you obtain the recordset set the recordset's connection object to "nothing" then you may update records using the updateBatch method...
0
 

Author Comment

by:polksolk
Comment Utility
I know how to make a disconnected recordset. The problem is how to set the Locktype-property when I use the command.execute method and not the open-method of the recordset. Like this:

Set rs = command.Execute

When I do like this Locktype is set to read only.
Here´s my code:


Set comOld = New Command
     With comOld
          .CommandType = adCmdStoredProc
          .CommandText = "GetOldOrder"  ' name on stored procedure
   
          ' skapar och lägger till input-parametrar och anger värde
          .Parameters.Append .CreateParameter("avdID", adInteger, adParamInput, , AvdID)
          .Parameters.Append .CreateParameter("orderno", adInteger, adParamInput, , OrderNr)
          .Parameters.Append .CreateParameter("totalsuma", adCurrency, adParamOutput)
          .Parameters.Append .CreateParameter("control", adInteger, adParamOutput)
          .Parameters.Append .CreateParameter("contact", adVarChar, adParamOutput, 40)
          .Parameters.Append .CreateParameter("orderstatus", adVarChar, adParamOutput, 48)
          .Parameters.Append .CreateParameter("sender", adVarChar, adParamOutput, 40)
         
          .ActiveConnection = cn
          Set rsLog = .Execute
          OrderSum = .Parameters("Totalsum").Value
          iKontroll = .Parameters("control").Value
          sjhkontakt = .Parameters("contact").Value
          Beststatus = .Parameters("orderstatus").Value
          Sandare = .Parameters("sender").Value
         
       End With
       Set comOld = Nothing
    Set rsLog.ActiveConnection = Nothing
0
 
LVL 2

Accepted Solution

by:
p_biggelaar earned 50 total points
Comment Utility
Forget about Set rs=Command.Execute

Your code should look like

'Do everything with you're command that's necessary then:

Set rs=new adodb.recordset
rs.CursorLocation=adUseClient
rs.CursorType=adOpenKeyset
rs.LockType=adLockBatchOptimistic
rs.open comOld
0
 
LVL 1

Expert Comment

by:mmips
Comment Utility
As I stated earlier you do not want to use the rs = command.execute...Use the open method for the recordset to allow you to set the cursor type and lockType...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 2

Expert Comment

by:p_biggelaar
Comment Utility
To mmips:

The difference between my comment and what you suggested is that I open the command (rs.Open comOld) while you describe the 'standard' open syntax.

rstEmployees.Open "employee", cnn1, , , adCmdTable

polksolk needs to use the command object, because he uses parameters, so your example is not accurate in the way that:
- you open a table
- when opening a command, you MUST use the connection specified by the command object, so even replacing the table name by the object would result in an error in that example.

Those were the main reasons why I posted my first comment. I wanted to tell you this, because I don't want to give you the impression that I was only 'copying' your comment.
0
 
LVL 3

Expert Comment

by:troywillmot
Comment Utility
If you have VB6, you could use DED (Data Environment Designer) which has a lock type property on the property page for a command if the returning recordset property is true. I assume that this affects the lock type for the recordset returned.
0
 
LVL 3

Expert Comment

by:troywillmot
Comment Utility
By the way, I don't use DED myself, 'cause I don't like it - but in cases where my boss has insisted I try it I haven't had any problems.
0
 

Author Comment

by:polksolk
Comment Utility
Thanks!
Works great.
0
 
LVL 2

Expert Comment

by:p_biggelaar
Comment Utility
you're welcome...
0
 
LVL 1

Expert Comment

by:mmips
Comment Utility
p_biggelaar,

Unfortunately I cut and pasted to much...I wanted to show how to set the values for a recordset...I know that He was using Stored Proceedures and that particular open method would not work...If you take the open method off of you comment it was a copy...And my second comment stated to use the open method for a recordset...rather than the execute method...Next time I'll have to be more careful about my cut and paste examples...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now