Question about executing stored procedures dynamically...
 
Home My Account Forum Try It! Buy It!
About Contact Us Site Map
StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



Question about executing stored procedures...Expand / Collapse
Author
Message
Posted 04/09/2008 8:41:29 PM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: 06/27/2008 5:57:22 PM
Posts: 436, Visits: 942
Consider that I have a table like this:

ColumnName: Stored Procedure Name
InsertRecord
DeleteRecord
UpdateRecord

What I want to be able to do is iterate through the table and execute the stored procedures at run time. The stored procedures though have a different number of parameters. InsertRecord has only one parameter, while DeleteRecord has two, etc.

How could I do this in code? Obviously I dont want to have to hard code the parameters in the VB code.

Should I use the DeriveParameters command? What would be the best way to execute these stored procedures when the parameters are unknown?

Thanks :-D
Post #15484
Posted 04/09/2008 10:20:31 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 8:47:41 AM
Posts: 4,104, Visits: 4,175
Well, like anything else, this can be done but the reason may change the approach.  You are going to need to know the number of parameters and the sprocs.  You can always query server for the sprocs and create a class that parses this information.  You would probably want to look at the sysobjects table.  It would be something like this (I'm just shootin from the hip here, so you may need to play with this a bit):

Select * from sysobjects where type = 'P' and category = 0

You can then start digging a little deeper to get the parms, etc. and build a logical command with the parameters, etc.

Post #15488
Posted 04/10/2008 6:54:12 AM


StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: StrataFrame Users
Last Login: 06/27/2008 5:57:22 PM
Posts: 436, Visits: 942
Thanks for the info Trent. I found something called SQLCommandBuilder.DeriveParameters last night and I'm going to look into it... might be what I need. ;-D Just thought I would post this in case it helps anyone else or someone else has used it and can confirm its what I need.
Post #15495
Posted 04/10/2008 8:02:10 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 8:47:41 AM
Posts: 4,104, Visits: 4,175
The SQLCommandBuilder is good and it may get you want you want.  That is also the very purpose of the DerivedParmameters...this class just has some limitations and can produce unoptimized queries...so that is the only thing I would caution about.
Post #15497
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 10:13am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.062. 10 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.