c# - Stored Procedure sql data insert error -
private void btninsert_click(object sender, eventargs e) { empcode = txtcode.text; empname = txtname.text; empcell = txtcell.text; empaddress = txtaddress.text; try { using (cmd = new sqlcommand(" empinsert ", conn)) { cmd.commandtype = commandtype.storedprocedure; cmd.parameters.add("@empcode", sqldbtype.varchar).value = empcode; cmd.parameters.add("@empname", sqldbtype.varchar).value = empname; cmd.parameters.add("@empcell", sqldbtype.varchar).value = empcell; cmd.parameters.add("@empaddress", sqldbtype.varchar).value = empaddress; conn.open(); cmd.executenonquery(); } messagebox.show("succesfully inserted", "congrates"); } catch (exception ex) { messagebox.show("can't insert there error :" + ex, "error"); } { conn.close(); } }
here stored procedure on sql
db side.
use gdk go create procedure dbo.empinsert @id varchar(10, @name varchar(10), @cell varchar(10), @address varchar(20) begin insert employeerecord(empcode,empname,empcell,empaddress) values( @id, @name, @cell, @address) end
i unable insert
in db.
kindly in regard
you have parameter name @id
in stored procedure passing @empcode
change
cmd.parameters.add("@empcode", sqldbtype.varchar).value = empcode;
to
cmd.parameters.add("@id", sqldbtype.varchar).value = empcode;
Comments
Post a Comment