Solved

Calling Stored Procedure VB.net

Posted on 2010-09-13
3
286 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
[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
  • 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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

733 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