473,387 Members | 1,464 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,387 software developers and data experts.

How to call SQL Server stored procedures in Visual Basic?

Hi,

I was wondering if someone could help me on this one.
I've made a stored procedure in SQL Server Enterprise Manager. When I call the stored procedure in Visual Basic I didn't succeed to return a SQL value.

I'm calling the procedure using the following VB source code:

Dim param1 As ADODB.Parameter
Dim aantal As Integer
Set ADOCMD = New ADODB.Command
frm_importeren.txt_importeren.Text)
Set param1 = ADOCMD.CreateParameter("aantal", adInteger, adParamOutput, 4)
With ADOCMD
.ActiveConnection = connSQL_dw
.CommandType = adCmdStoredProc
.CommandText = "chck_geslacht"
.CommandTimeout = 0
.Parameters.Append param1
.Execute , param1
.Parameters.Refresh
End With
Set ADOCMD = Nothing
Set param1 = Nothing

My stored procedure in SQL server:
CREATE PROCEDURE chck_geslacht @Aantal INT OUTPUT
AS

SELECT Geslachtscode
FROM imptmp_bevpeil
WHERE (imptmp_bevpeil.Geslachtscode NOT IN
(SELECT DISTINCT Codering_Geslacht.Geslachtscode
FROM Codering_Geslacht))
set @Aantal=833
return @aantal
GO

SQL server doesn't return the value I'm expecting (833).
Oct 12 '06 #1
1 13767
willakawill
1,646 1GB
You must assign the return value of the execute command to a recordset.

Here it is from MSDN:

Expand|Select|Wrap|Line Numbers
  1. This example shows the execution of the sp_who SQL Server system stored procedure:
  2.  
  3. Dim cn As New ADODB.Connection
  4. Dim cmd As New ADODB.Command
  5. Dim rs As New ADODB.Recordset
  6.  
  7. cn.Provider = "sqloledb"
  8. cn.Properties("Data Source").Value = "MyServerName"
  9. cn.Properties("Initial Catalog").Value = "northwind"
  10. cn.Properties("Integrated Security").Value = "SSPI"
  11. cn.Open
  12.  
  13. Cmd.ActiveConnection = cn
  14. Cmd.CommandText = "sp_who"
  15. Cmd.CommandType = adCmdStoredProc
  16.  
  17. Set rs = Cmd.Execute
  18. Debug.Print rs(0)
  19. rs.Close
  20.  
  21.  
Oct 12 '06 #2

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

Similar topics

9
by: Rich May | last post by:
Afternoon all, Apologies for cross-posting but as my query covers both Access and SQL Server I thought I'd send it both! I have inherited a project to migrate a fairly complex series of...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
3
by: Mariusz | last post by:
I want to write function to call another function which name is parameter to first function. Other parameters should be passed to called function. If I call it function('f1',10) it should call...
5
by: gilles27 | last post by:
I've ready many of the posts on this and other newsgroups in which people describe working practices for source control of database scripts. We are looking to implement something similar in my...
11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
1
by: Matt Alanzo | last post by:
On another newsgroup an Access knowledgable party posted: >You should be able to connect an Access ADP to an existing SQLExpress >database running in SQLS 2000 compatibility mode. The only thing...
2
by: Gary | last post by:
Hi Al I have the following parameters in an oracle function PACKAGE BODY ALLO A ------------------------------------------------------------------------------- FUNCTION ITEM...
13
by: Marcin Wasilewski | last post by:
Hi, How to call procedure, which is on SQL Server from Access using visual basic? Thanks, mw
10
by: tlyczko | last post by:
Hello, We have Access databases (backends) that will eventually be consolidated into a SQL Server database, to facilitate data reporting, analysis, etc. Some queries in one Access database...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.