Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / September 2006

Tip: Looking for answers? Try searching our database.

stored procedure arguments

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
benscribe - 29 Sep 2006 18:43 GMT
I've looked high and low for this information and haven't found it anywhere.
Is there a way to pass arguments to a stored procedure being used by a
selectcommand. I've seen mention of SelectCommand.Perameter.Add() but that
doesn't seem work.
Daniel - 29 Sep 2006 19:46 GMT
This is a example stored procedure with values passed in

string storedProc = "sp_MyProcedure";

SqlCommand sc = new SqlCommand(MyProcedure, _conn);
sc.CommandType = CommandType.StoredProcedure;

sc.Parameters.Add("@aVar", SqlDbType.BigInt, 8);
sc.Parameters.Add("@anotherVar", SqlDbType.BigInt, 8);
sc.Parameters.Add("@anotherVar2", SqlDbType.Money, 8);

sc.Parameters["@aVar"].Value = someValue;
sc.Parameters["@anotherVar"].Value = some_other_value;
sc.Parameters["@anitherVar2"].Value = and_another_value;

_conn.Open(); //open your connection
sc.ExecuteNonQuery();  ///execute procedure
_conn.Close();   //close connection

> I've looked high and low for this information and haven't found it
> anywhere.
> Is there a way to pass arguments to a stored procedure being used by a
> selectcommand. I've seen mention of SelectCommand.Perameter.Add() but that
> doesn't seem work.
benscribe - 29 Sep 2006 19:54 GMT
Thanks very much for that, Daniel. The core of my question is how can I, if
possible, execute that inside a gridview selectcommand syntax?

> This is a example stored procedure with values passed in
>
[quoted text clipped - 20 lines]
> > selectcommand. I've seen mention of SelectCommand.Perameter.Add() but that
> > doesn't seem work.
Daniel - 30 Sep 2006 01:54 GMT
oh i see you want, on selecting an item in a gridiew to fire that stored
procedure am i right?

If i am you just hook the event for gridview selection changed and fire it
off there, passing in the vars required.

> Thanks very much for that, Daniel. The core of my question is how can I,
> if
[quoted text clipped - 25 lines]
>> > that
>> > doesn't seem work.
martin.zarate@gmail.com - 29 Sep 2006 20:40 GMT
For less verbose syntax, Microsoft provides an AutoSproc Sql Server
codegen tool that you can use to autogenerate stored procedure
functions - all you have to do is provide a dotnet interface to your
stored procedures and it will build the corresponding ADO.Net calls.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/a
utousa2.asp


> This is a example stored procedure with values passed in
>
[quoted text clipped - 20 lines]
> > selectcommand. I've seen mention of SelectCommand.Perameter.Add() but that
> > doesn't seem work.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.