c# - Return IDENT_CURRENT which was inserted -


i have insert sqlcommand , need display after insert ident_current inserted these values

sqlcommand sc = new sqlcommand("insert kliplat (datum,text,castka,akce,subkey,priznak,rocnik) values (@datum,@text,@castka,@akce,@subkey,@priznak,@rocnik)", spojeni);          spojeni.open();           sc.parameters.addwithvalue("@subkey", vyber_id_kli);          sc.parameters.addwithvalue("@akce", vyberakce);          sc.parameters.addwithvalue("@priznak", vyberplat);          sc.parameters.addwithvalue("@datum", maskedtextbox1.text);          sc.parameters.addwithvalue("@text", textbox1.text);          sc.parameters.addwithvalue("@castka", textbox2.text);          sc.parameters.addwithvalue("@rocnik", rocnik);           sc.executereader();          spojeni.close(); 

this ident_current is: integer identity primary key

now dealing issue this:

sqlcommand comm = new sqlcommand("select ident_current ('mytable')", conn);                  spojeni.open();                  int max = convert.toint32(comm.executescalar());                   spojeni.close(); 

but found out extremely hazardous do.

thank time reading this.

you use command returns newly inserted id:

sqlcommand sc = new sqlcommand(@"     insert kliplat (datum,text,castka,akce,subkey,priznak,rocnik)      values (@datum,@text,@castka,@akce,@subkey,@priznak,@rocnik);     select scope_identity();     ", spojeni); ... var newidentity = (long) sc.executescalar(); 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -