Solved

Locktype with Command-object

Posted on 2000-02-16
11
417 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add text to end of existing text in file 16 70
Windows 10 start screen issues 9 54
MS Access - Capture pressed key onclick 4 32
Sub or Function is not defined 6 25
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

816 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