473,396 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Updating Data in a Recordset (Stored Procedure)

19
Hi folks, I'm just learning how to use MS Access as a front end for SQL Server, and have a question:

I have a stored procedure that returns a set of records from a SQL Server and loads it into a form in my Access application. This works as intended, but I'm having trouble trying to figure out how to modify records on the form... whenever I try i get the error that says youc an't modify this data because its based on an expression.

i'm just learning stored procedures in access so i was wondering if anybody could help. the code that populates the form is below.

Basically I'm wondering if I can have the application automatically update data without having to create a 2nd procedure to push changes back to the server.

Expand|Select|Wrap|Line Numbers
  1. Set gcn = Nothing
  2.     Dim sConnect As String
  3.     sConnect = "Driver={SQL Server};Server=XXXX;Database=XXXXX;Trusted_Connect  ion=Yes;"
  4.  
  5.     Set gcn = New ADODB.Connection
  6.     gcn.CursorLocation = adUseClient
  7.     gcn.Open sConnect
  8.  
  9.     'On Error GoTo ExitProcedure
  10.     Dim rs As ADODB.Recordset
  11.     Set rs = New ADODB.Recordset
  12.     'Call doConnect
  13.  
  14.     Dim cmd As ADODB.Command
  15.     Set cmd = New ADODB.Command
  16.  
  17.     With cmd
  18.         .CommandText = "my_procedure"
  19.         .CommandType = adCmdStoredProc
  20.         .Parameters.Append .CreateParameter("@parm1", adChar, adParamInput, 15, Me.cbxData_Set)
  21.         Set .ActiveConnection = gcn
  22.     End With
  23.  
  24.     Set rs = New ADODB.Recordset
  25.     rs.CursorLocation = adUseServer
  26.     rs.Open cmd, , adOpenStatic, adLockPessimistic
  27.  
  28.     Set rs = cmd.Execute
  29.  
  30.     Set Me.Form.Recordset = rs
Nov 2 '07 #1
6 6586
ADezii
8,834 Expert 8TB
Hi folks, I'm just learning how to use MS Access as a front end for SQL Server, and have a question:

I have a stored procedure that returns a set of records from a SQL Server and loads it into a form in my Access application. This works as intended, but I'm having trouble trying to figure out how to modify records on the form... whenever I try i get the error that says youc an't modify this data because its based on an expression.

i'm just learning stored procedures in access so i was wondering if anybody could help. the code that populates the form is below.

Basically I'm wondering if I can have the application automatically update data without having to create a 2nd procedure to push changes back to the server.

Expand|Select|Wrap|Line Numbers
  1. Set gcn = Nothing
  2.     Dim sConnect As String
  3.     sConnect = "Driver={SQL Server};Server=XXXX;Database=XXXXX;Trusted_Connect  ion=Yes;"
  4.  
  5.     Set gcn = New ADODB.Connection
  6.     gcn.CursorLocation = adUseClient
  7.     gcn.Open sConnect
  8.  
  9.     'On Error GoTo ExitProcedure
  10.     Dim rs As ADODB.Recordset
  11.     Set rs = New ADODB.Recordset
  12.     'Call doConnect
  13.  
  14.     Dim cmd As ADODB.Command
  15.     Set cmd = New ADODB.Command
  16.  
  17.     With cmd
  18.         .CommandText = "my_procedure"
  19.         .CommandType = adCmdStoredProc
  20.         .Parameters.Append .CreateParameter("@parm1", adChar, adParamInput, 15, Me.cbxData_Set)
  21.         Set .ActiveConnection = gcn
  22.     End With
  23.  
  24.     Set rs = New ADODB.Recordset
  25.     rs.CursorLocation = adUseServer
  26.     rs.Open cmd, , adOpenStatic, adLockPessimistic
  27.  
  28.     Set rs = cmd.Execute
  29.  
  30.     Set Me.Form.Recordset = rs
Can you post the contents of "my_procedure"?
Nov 2 '07 #2
binky
19
The stored procedure is below. It's a simple SQL query that uses parameters passed from the application.

Expand|Select|Wrap|Line Numbers
  1. IF OBJECT_ID('my_procedure') IS NOT NULL
  2.     DROP PROCEDURE my_procedure
  3. GO
  4.  
  5. CREATE PROCEDURE dbo.my_procedure
  6.    (@p_cPrcsNm   CHAR    (15)     
  7.    ,@p_cErrMsg   CHAR    (75)      
  8.    ,@p_vButton   int     
  9.    ,@p_vAssgnCd  VARCHAR (3)       
  10.    ,@p_vRouteCd  VARCHAR (4)       
  11.    ,@p_vStatusCd CHAR    (10)     
  12.    )
  13. AS
  14.  
  15. BEGIN
  16.    SELECT a.*, b.* FROM dbo.cs_br AS a
  17.    LEFT JOIN dbo.cs_tr AS b
  18.    ON a.cv_id = b.cv_id
  19.    WHERE a.prcs_nm = @p_cPrcsNm
  20.    and (@p_cErrMsg IS NULL OR a.err_msg = @p_cErrMsg)
  21.    and (@p_vStatusCd IS NULL OR a.status_cd = @p_vStatusCd)
  22.    and (@p_vAssgnCd IS NULL OR LTRIM(RTRIM (b.assgn_cd)) = @p_vAssgnCd)
  23.    and (@p_vRouteCd IS NULL OR b.route_cd = @p_vRouteCD)
  24. END
  25.  
  26. GO
Nov 5 '07 #3
binky
19
/bump for anybody that might be able to help :)
Nov 5 '07 #4
ADezii
8,834 Expert 8TB
/bump for anybody that might be able to help :)
Hello binky, I am by no means an expert on Stored Procedures, but here are a few of my initial observations. I hope that they will point you in the right direction:
  1. The Recordset that is dynamically assigned to your Form was opened via a Static Cursor Type, try a Keyset Cursor instead as in:
    Expand|Select|Wrap|Line Numbers
    1. rs.Open cmd, , adOpenKeyset, adLockPessimistic
  2. my_procedure accepts 6 Input Parameters, but I see only 1 being appended to the Command Objects Parameters Collection:
    Expand|Select|Wrap|Line Numbers
    1. .Parameters.Append .CreateParameter("@parm1", adChar, adParamInput, 15, Me.cbxData_Set)
  3. You stated that Input Parameters are being passed from the Application, but how?
  4. The SQL Statement as defined in your Stored Procedure, involves a Left Outer Join. Perhaps this could be the reason why the data is not Updateable? Try a Standard Inner Join and see if the results are the same.
  5. Fields based on Expressions are, in fact, not Updateable but I see no indication of this.
  6. Fields on Forms based on a 1 to Many Join from a Stored Procedure are Updateable if they are in the most-many Table and this Table has been specified as the Unique Table for the Form. Is this your case?
  7. You are using Integrated Security within your Connection String (Trusted_Connection= Yes). Do you have the required Permissions on the Server?
  8. When you use the Execute() Method of a Command Object with Parameters, the resulting Recordset is Read Only. Try replacing these 2 lines:
    Expand|Select|Wrap|Line Numbers
    1. rs.Open cmd, , adOpenStatic, adLockPessimistic
    2. Set rst = cmd.Execute
    with this single line:
    Expand|Select|Wrap|Line Numbers
    1. rs.Open cmd, , adOpenKeyset, adLockOptimistic, adCmdStoredProcedure
  9. As far as I know, you shouldn't need a 2nd Procedure to 'push' data back to the Server.
  10. Try each point in turn and see what happens. Keep me informed as to your progress, since you peaked my interest with this one.
Nov 6 '07 #5
binky
19
Thanks for the reply :)

I might have found a workaround, and that's by migrating everything from a MDB project into an ADP project. Then I can use my existing procedure as the recordsource on a form and Access apparently handles the edits with all the appropriate record locks automatically.

But I will also try your suggestions, and see what works best :)
Nov 7 '07 #6
ADezii
8,834 Expert 8TB
Thanks for the reply :)

I might have found a workaround, and that's by migrating everything from a MDB project into an ADP project. Then I can use my existing procedure as the recordsource on a form and Access apparently handles the edits with all the appropriate record locks automatically.

But I will also try your suggestions, and see what works best :)
Hi folks, I'm just learning how to use MS Access as a front end for SQL Server, and have a question:
Sorry binky, but I was under the impression that you were using an Access Project.
Nov 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Roy Adams | last post by:
Hi everyone I'm trying to build a shopping cart app using a db the part I'm stuck on is the fact that, if someone adds a product that they have previously added to the cart. I've got it set up to...
15
by: Jarrod Morrison | last post by:
Hi All Im generally a vb programmer and am used to referencing multiple records returned from a query performed on an sql database and im trying to move some functions of my software into sql...
3
by: Ryan.Chowdhury | last post by:
This is a general question regarding the use of view and stored procedures. I'm fairly new to databases and SQL. I've created a SQL database using an Access Data Project ("ADP") and I'm...
2
by: M Wells | last post by:
Hi All, I'm trying to track down a mysterious problem we're experiencing in which updates and inserts to tables in our mssql2k server appear to be 'disappearing.' To explain our situation: ...
2
by: Josh Strickland | last post by:
I am attempting to create an Access database which uses forms to enter data. The issue I am having is returning the query results from the Stored Procedure back in to the Access Form. ...
6
by: Wojciech Wendrychowicz | last post by:
Hello to All, I'm trying to retrieve records from AS/400 in an VBA application. So, I've made an RPG program, then a stored procedure wchich calls that RPG program, and finally some VBA code to...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
1
by: lemes_m | last post by:
Hi All! I have very big problem and I can't continue my Work on my project until i solve it. Here is the situation: TblCalculations FldCalcId FldArticle FldQuantity FldPrice ...
20
by: TC | last post by:
I need an automated procedure to copy data from an Access table to a SQL Server table. Speed is important. What is the recommended technique? I can export the data from Access, copy it via FTP,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.