c# - Error when inserting multiple json string -
this code work can can insert 1 json string sql db. if json string multiple insert 1 json string, error
usp_insert_schedule has many arguments specified.
can give me links of tutorial or guide me @ least.
using newtonsoft.json; //object root public class jobt { public string empid { get; set; } public string status { get; set; } } private void insrt_jstring() { iscedule isc = new iscedule(); //sql stored proc string query = isql.stored_procedure_sch_add; //sql class insert iemp usr = new iemp(query); string barc = txtbarcode.text.trim(' '); string ddate = isc.get_date(); //http://get w/ barc & ddate param string input = isc.jvalue(barc, ddate); string input = @"{""empid"":""b14"",""status""}{""empid"":""b15"",""status"":""morning""}"; var output = input.split(new[] { '{', '}' }, stringsplitoptions.removeemptyentries) .select(x => "{" + x + "}") .tolist(); foreach (var json in output) { jobt ob = jsonconvert.deserializeobject<jobt>(json); usr.insert_schedule(ob.empid, ob.status); } } //class insert_schedule public class iemp: icon { public string query; public string comstring { get; protected set; } public iemp(string coms): base(coms) { this.query = coms; comm.parameters.clear(); comm.commandtype = commandtype.storedprocedure; comm.commandtext = this.comstring; comm.connection = conn; } //schedule public void insert_schedule(string empid, string status) { comm.parameters.addwithvalue("@empid", empid); comm.parameters.addwithvalue("@status", status); comm.executenonquery(); } }
stored proc
create proc [dbo].[usp_insert_schedule] @empid [varchar](32), @status [varchar](20) insert schedule(ctrl_id, status) values (@empid, @status)
Comments
Post a Comment