asp.net - Run stored procedure in C#, pass parameters and capture the output result -
this simple task want acheive asp.net makes quite difficult, next impossible. followed question running stored procedure in c# button found out executenonquery
not return output query.
i tried other approach can't seem pass paremeters in way
sqlconnection myconnection = new sqlconnection(myconnectionstring); sqlcommand mycommand = new sqlcommand(); mycommand.commandtype = commandtype.storedprocedure; mycommand.commandtext = "usp_getcustomer"; mycommand.selectparameter <-- not exist
can write simple code, how can implement it? passing @username
, @month
(both character strings) stored procedure , returns number want capture , assign label control.
thank you
the output query this. runs complex query, create temp table , runs
select @@rowcount
and capturing that.
don't use
sqlcommand.executenonquery()
if want data result set.make sure procedure uses
set nocount on
then use
sqlcommand.executescalar()
return (int)mycommand.executescalar(); // value of select @@rowcount
edit: parameters:
mycommand.parameters.addwithvalue("@username","jsmith"); mycommand.parameters.addwithvalue("@month","january");
Comments
Post a Comment