Solved

Calling Stored Procedure VB.net

Posted on 2010-09-13
3
284 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with exporting to excel 4 36
Get distinct values from excel or comm seperated file 4 30
VB.net capture  result of a SQL query in variables 3 20
Visual studio 2015 1 21
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

856 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