sql - Select SCOPE_IDENTITY not executing after insert statement; -


i try id of last inserted t ouristin table put selct scope_identity; after insert query.

the problem when try show id of inserted tourist in label - nothing happens. (only insert query executed);

string insertsql = "insert tourist (excursion_id, excursion_date_id, name_kir,midname_kir, lastname_kir)";     insertsql += "values (@excursion_id, @excursion_date_id, @name_kir,@midname_kir, @lastname_kir);select scope_identity()";                  string connectionstring = "data source = localhost\\sqlexpress;initial catalog=excursion;integrated security=sspi";                 sqlconnection con = new sqlconnection(connectionstring);                 sqlcommand cmd = new sqlcommand(insertsql, con);                 cmd.parameters.addwithvalue("@excursion_id", convert.toint32(mynew2));                 cmd.parameters.addwithvalue("@excursion_date_id", convert.toint32(mynewnewstring));                 cmd.parameters.addwithvalue("@name_kir",tx888.text);                 cmd.parameters.addwithvalue("@midname_kir",tx888_1.text);                 cmd.parameters.addwithvalue("@lastname_kir",tx888_2.text);                    int added = 0;                 try                 {                     con.open();                     added = (int)cmd.executescalar();                      if (added > 0)                     {                         lblproba.text+=added.tostring();                       }                  }                 catch (exception ex)                 {                     //lblresult.text = ex.message;                   } 


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -