Search Results

Search found 1 results on 1 pages for 'gligom'.

Page 1/1 | 1 

  • try catch finally

    - by gligom
    Maby this is simple for you, but for me is not. I have this code: Private int InsertData() { int rezultat = 0; try { if (sqlconn.State != ConnectionState.Open) { sqlconn.Open(); } rezultat = (int)cmd.ExecuteScalar(); } catch (Exception ex) { lblMesaje.Text = "Eroare: " + ex.Message.ToString(); } finally { if (sqlconn.State != ConnectionState.Closed) { sqlconn.Close(); } } return rezultat; } Is just for inserting a new record in a table. Even if this throw an error "Specified cast is not valid." "rezultat=(int)cmd.ExecuteScalar();" - the code is executed and the row is inserted in the database, and the execution continues. Why it continues? Maby i don't understand the try catch finally yet Smile | :) Thank you!

    Read the article

1