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.

  1. don't use sqlcommand.executenonquery() if want data result set.

  2. make sure procedure uses set nocount on

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

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -