Solved

Locktype with Command-object

Posted on 2000-02-16
11
428 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 1

Expert Comment

by:mmips
ID: 2527275
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
ID: 2527283
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
ID: 2527376
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 2

Accepted Solution

by:
p_biggelaar earned 50 total points
ID: 2527523
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
ID: 2527688
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
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2527760
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
ID: 2529795
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
ID: 2529799
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
ID: 2530195
Thanks!
Works great.
0
 
LVL 2

Expert Comment

by:p_biggelaar
ID: 2530514
you're welcome...
0
 
LVL 1

Expert Comment

by:mmips
ID: 2531673
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

690 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