i trying execute stored procedure in sql server database asp.net mvc project. have set in way can use testing purposes, why variable "proceduretest" constant value (i know "2044" existing record in database). change once accomplish successful run. also, know stored procedure works because have executed in sql server management studio successfully. procedure has task of adding id 1 table another, have yet see appear in table. not receiving error in catch block kind of lost @ moment. use help.
try { using (var connection = new sqlconnection(connectionstring)) { connection.open(); int proceduretest = 2044; var command = new sqlcommand("select id images id = @id", connection); var paramdate = new sqlparameter("@id", proceduretest); command.parameters.add(paramdate); var reader = command.executereader(); while (reader.read()) { var storedproccommand = new sqlcommand("exec addtonotificationtable @id", connection); var paramid = new sqlparameter("@id", reader.getint32(0)); storedproccommand.parameters.add(paramid); command.executenonquery(); } } } catch (exception e) { string exceptioncause = string.format("an error occurred: '{0}'", e); system.io.file.writealltext(@"c:\users\nathan\documents\visual studio 2013\projects\mvcimageupload\uploads\exception.txt", exceptioncause); } stored procedure:
create procedure addtonotificationtable @id int insert notificationtable (id) select id images id = @id
change code this
while (reader.read()) { var storedproccommand = new sqlcommand("exec addtonotificationtable @id", connection); var paramid = new sqlparameter("@id", reader.getint32(0)); storedproccommand.parameters.add(paramid); storedproccommand.executenonquery(); }
Comments
Post a Comment