Solved

Calling Stored Procedure VB.net

Posted on 2010-09-13
3
283 Views
Last Modified: 2012-05-10
Hi
What I am trying to do (Excuse syntax, its not meant to run, just a roadmap.)
crate MANY stored procedures
Most have up to 3 parameters
I want my vb code to call procedures and supply only relevant parameters
So my stored procedure is like
alter procedure
as
Param1 int = 0, Param2 int = 0, Param3 char(20) = ' ', param4 char(20) = ' ', param5 Datimtime = getdate(), Param6 Datetime = GetDate()
My first procedure uses Param1 and param5
My Second procedure uses Param2 and param4
My first procedure uses Param1 and param6
Etc etc etc
Can the code be written to only supply these values or do I have to supply for alll params.
Hope this makes sense
And if so an example woould be great
Thanks

0
Comment
Question by:JamesAnthony
  • 2
3 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 33663723
you cannot do it so that you only specify param2 and 4 as you want. The only possibility is what's described below:
http://geekswithblogs.net/whiletrue/archive/2009/02/28/optional-parameters-in-sql-stored-procedures.aspx 
0
 
LVL 9

Accepted Solution

by:
valkyrie_nc earned 500 total points
ID: 33663738
So long as you have defaults assigned for the input parameters in the stored procedure, you can send in only the params you prefer.  The declaration you have above (Param1 int = 0, Param2 int = 0) is perfect.  If any param is required by the proc, just remove the = [whatever].

hth

valkyrie_nc
0
 
LVL 41

Expert Comment

by:ralmada
ID: 33663790
the other possibility is that you try something like below
 

exec yourprocedure @param2 = 1, @param4 = 'something'

exec yourprocedure @param1 = 0, @param5 = 'something'

Open in new window

0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SHOWPLAN permission denied in database 'AdventureWorks'. 13 100
VS.net 2010 11 34
SQL query with cast 38 42
convert null in sql server 12 33
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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