c# - calling procedure from sql -
i coding winform application call procedure in datagrid. have method define parameters of procedure
public int add_nastavenie(out int typnastav, int nastavid, string hod) { resetparameters(); cmd.commandtext = "add_nastav"; cmd.commandtype = commandtype.storedprocedure; sqlparameter sqlparameter; var sqlparameterout = new sqlparameter("@typnastav", sqldbtype.int); sqlparameterout.direction = parameterdirection.output; sqlparameter = new sqlparameter("@nastavenieid", sqldbtype.int); sqlparameter.direction = parameterdirection.input; sqlparameter.value = nastavid; cmd.parameters.add(sqlparameter); sqlparameter = new sqlparameter("@hodnota", sqldbtype.nvarchar, 100); sqlparameter.direction = parameterdirection.input; sqlparameter.value = hod; cmd.parameters.add(sqlparameter); var sqlparameterret = new sqlparameter("retvalue", sqldbtype.int); sqlparameterret.direction = parameterdirection.returnvalue; cmd.executenonquery(); typnastav = (int)sqlparameterout.value; return (int)cmd.parameters["retvalue"].value; }
then call procedure way
dataconnector.add_nastavenie(typnastav,nastavid,hod);
i have error argument 1 must passed 'out' keyword
i change dataconnector.add_nastavenie(out typnastav,nastavid,hod);
error dissapear application not working, procedure nothing .
my try catch exception show : procedure or function 'add_nastav' expects parameter '@typnastav', not supplied.
can find solution ? .
you haven't added output
parameter stored procedure expecting:
cmd.parameters.add(sqlparameterout);
Comments
Post a Comment