asp.net - C# is returning exception: Procedure has no parameters and arguments were supplied -
i apologise formatting. new programming , new site, try , make question clear possible.
i have webform accessing/modifying customer database. have button entering new customers details automatically assign id number getting highest id number database, , incrementing 1 (and posting form textbox).
this code have written:
protected void btnnew_click(object sender, eventargs e) { clear(); command.connection = conn; command.commandtype = commandtype.storedprocedure; command.commandtext = "newcustomer"; conn.open(); sqlparameter maxid = new sqlparameter(); maxid.parametername = "@maxid"; maxid.sqldbtype = sqldbtype.int; maxid.direction = parameterdirection.output; command.parameters.add(maxid); command.executenonquery(); newcustid = convert.toint32(maxid.value); newcustid += 1; txtcustid.text = (newcustid).tostring(); txtcustid.databind(); conn.close(); }
this stored procedure:
create procedure newcustomer (@maxid int output) begin select @maxid = max(custid) dbo.customer end
i have tried many different ways of coding it, nothing seems work. code have posted has exception @ executenonquery
saying arguments supplied , procedure has no parameters. when place command.parameters.add(maxid);
underneath executenonquery
, returns 1.
i ran sql query alone see happen , returns correct answer in unnamed cell. reason column name disappears when comes up. when try use c# code access unnamed cell, can't seem access because column 'custid' "doesn't exist".
with code, know sql command executing, , c# code increments 1, seems return value getting 0.
i appreciated ideas can on how fix this. thank you.
edit: have tried: datatable table = new datatable(); adapter.fill(table); newcustid = table.rows[0].field("custid");
(this said 'custid' column didn't exist)
change code following , try again:
clear(); command.connection = conn; command.commandtype = commandtype.storedprocedure; command.commandtext = "newcustomer"; conn.open(); newcustid = convert.toint32(cmd.executescalar().tostring()); newcustid += 1; txtcustid.text = newcustid.tostring(); conn.close();
and stored procedure is:
create procedure newcustomer ( ) begin select max(custid) dbo.customer; end
Comments
Post a Comment