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
> 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.