[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Call Stored Proc from VB that will allow updating to tables

Posted on 2004-10-19
13
Medium Priority
?
189 Views
Last Modified: 2010-05-02
I get a runtime error 3251 Current Recordset does not support updating.  This may be a limitation of the provider or of the selected locktype.

The following is the code I am using to call the stored proc.:

Dim rstProgram As ADODB.Recordset
Dim m_cmd As New ADODB.Command

Set rstProgram = New ADODB.Recordset

With m_cmd
    .ActiveConnection = conSQL
    .CommandType = adCmdStoredProc
    .CommandText = "sp_AllProgram"       ' Stored Procedure name.
End With

Set rstProgram = m_cmd.Execute
rstProgram.MoveFirst

 With rstProgram
        .AddNew                                'HERE IS WHERE I GET THE ERROR
          ......
          ......


What am i doing wrong?
         
0
Comment
Question by:JoannieJefferson
[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
  • 4
  • 3
  • +2
13 Comments
 
LVL 10

Assisted Solution

by:fds_fatboy
fds_fatboy earned 120 total points
ID: 12347125
You cannot update a sp like this. This is a Server Side Cursor. Instead of a SP use a View.
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12347178
PS:

Server side cursors i.e. dynasets should not in general be used in multiuser environments. In fact every single DBA I have ever met would disembowel me for unleashing one on their database.
0
 

Author Comment

by:JoannieJefferson
ID: 12347252
Instead of a SP use a View.

I am not familiar with views...How would I set up a view, call it from vb and update records?
0
Industry Leaders: 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!

 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12348578
Wat dbms are you using?
0
 

Author Comment

by:JoannieJefferson
ID: 12348702
I am using SQL Server 2000 with Visual Basic 6.0
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12348996
Have I misunderstood what you are trying to acheive?

Are you  trying to add new rows into the database, or just add extra records into your recordset?
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 690 total points
ID: 12349101
Instead of using the AddNew method of the Recordset, you could use the "INSERT INTO TableName..." syntax to insert data into the databases. These statements can be executed using YourConnnection.Execute
0
 

Author Comment

by:JoannieJefferson
ID: 12350500
Does anyone know how to call a view from sql server 2000 from vb 6?
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 690 total points
ID: 12350525
rs.open "select * from ViewName",YourConnection
0
 
LVL 10

Assisted Solution

by:anv
anv earned 390 total points
ID: 12355121
hi JoannieJefferson

u cannto do what u r trying to achiev using a Stored Procu\dure in this fashion..

if u want to use the stored procedure to insert data into the table for that u need to

pass parameters to the SP which will be the values u want to insert into the database..

for eg.

'here is ur procedure u created in SQL server..

Create Proc abc1(p1,p2,p3)
  insert into table t1 values(p1,p2,p3)
end proc

here is ur code in VB...

str1 = "abc1('" & Item1 & "','" & Item2 & "',"' & Item3 & "'")

conSQL.Execute str1
0
 

Expert Comment

by:niranjanrampure
ID: 12419878
what are u trying to do with .addnew
as said fds_fatboy  u cant insert data into a table without passing parameters to sp.
also insert statement is better than recordse.addnew.pls explain u r probleum in detail
0
 

Author Comment

by:JoannieJefferson
ID: 12425149
Here is a sample procedure:

CREATE PROCEDURE sp_Report  @ProgramID nchar(20), @dtStartDate datetime , @dtEndDate datetime
AS

SELECT T1.x,T2.z,T2.y
FROM TABLE1
INNER JOIN TABLE2
ON T1.TABLE1ID = T2.TABLE2ID
WHERE (((T1.TABLE1.ID)=@ProgramId)
AND ((T2.TABLE2Date)> @StartDate)
AND ((T2.TABLE2Date)< @EndDate)
ORDER BY TABLE1.CardHolderLastName
GO


1. I want to know how to call this procedure (sp_Report) from VB and pass the parameters to this procedure.
2. Can I use the recordset to update or add new records to the table?  If so how?
3. What is the best way for me to achieve what i am trying to do using store procedures?
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 690 total points
ID: 12425219
2. No

3. You have to write INSERT INTO sql queries
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Suggested Courses

649 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