By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,054 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,054 IT Pros & Developers. It's quick & easy.

stored procedure arguments

P: n/a
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.
Sep 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

"benscribe" <be*******@discussions.microsoft.comwrote in message
news:D9**********************************@microsof t.com...
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.

Sep 29 '06 #2

P: n/a
Thanks very much for that, Daniel. The core of my question is how can I, if
possible, execute that inside a gridview selectcommand syntax?

"Daniel" wrote:
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

"benscribe" <be*******@discussions.microsoft.comwrote in message
news:D9**********************************@microsof t.com...
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.


Sep 29 '06 #3

P: n/a
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/de...l/autousa2.asp

Daniel wrote:
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

"benscribe" <be*******@discussions.microsoft.comwrote in message
news:D9**********************************@microsof t.com...
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.
Sep 29 '06 #4

P: n/a
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.
"benscribe" <be*******@discussions.microsoft.comwrote in message
news:64**********************************@microsof t.com...
Thanks very much for that, Daniel. The core of my question is how can I,
if
possible, execute that inside a gridview selectcommand syntax?

"Daniel" wrote:
>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

"benscribe" <be*******@discussions.microsoft.comwrote in message
news:D9**********************************@microso ft.com...
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.



Sep 30 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.