c# - I'm not getting return value of stored procedure. var @id is not supplied.? -


this sql server stored procedure insert data:

alter proc insert_stud1      @name varchar(20),     @mobile int,     @id int output begin      insert stud1 values (@name, @mobile)      set @id = @@identity; end 

corresponding c#

cmd.commandtype = commandtype.storedprocedure;  cmd.parameters.add("@name",sqldbtype.varchar,20); cmd.parameters.add("@mobile",sqldbtype.int); var ret = cmd.parameters.add("@i", sqldbtype.int); cmd.parameters["@name"].value=textbox1.text; cmd.parameters["@mobile"].value=int.parse(textbox2.text);  cmd.commandtext="insert_stud1";  con.open(); cmd.executenonquery(); messagebox.show(ret.value.tostring()); con.close(); 

you send "@i" instead of "@id"


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -