Solved

Locktype with Command-object

Posted on 2000-02-16
11
422 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 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