stored procedure arguments

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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 said:
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 said:
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.
 
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/autousa2.asp
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 said:
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.
 
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 said:
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 said:
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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top