update row to database RRS feed

  • Question

  • Hi All

    I'm trying to simulate database update errors whild updatating a row to database 

    I use a winform a typed Dataset and TableAdapter.

    Then a fill a datatable form the DB (By AdapterFill)  and I read a row from Datatable and show all data in the winform textboxs.

    Then I procede to modify the data. 

    Before i click on a Button to confirm the new data, by SSMS a delete from database the same row.

    The I confirm all data and send the query to TableAdapter to update Database. with this code

                LastRegioneID = TA_Regioni.UpdateQuery(currentrow.RegioneCk, currentrow.RegioneDes, currentrow.RegioneNazioneID, currentrow.RegioneID)
     Catch sqlex As SqlException
                mDALHasSqlException = True
                mDALSqlException = sqlex
     Catch currex As DBConcurrencyException
                mDALHasCurrException = True
                mDALCurrException = currex
     Catch genex As Exception
                mDALHasGenericException = True
                mDALGenericException = genex
     End TRY

    And this is the tableadapert query for update DB row

    UPDATE [Tabel].[TabRegioni] SET [RegioneCk] = @RegioneCk, [RegioneDes] = @RegioneDes, [RegioneNazioneID] = @RegioneNazioneID 
    FROM Tabel.TabRegioni WHERE (RegioneID = @RegioneID)

    But I do not get any exception by the try .... catch ....

    I must say that every thing works well with other exception (like error 2601 or 208 or 547 ) but not in this case

    Why ??

    • Edited by Claudio111 Thursday, January 24, 2019 7:54 PM
    Thursday, January 24, 2019 7:37 PM


  • Hello,

    All Update SQL have a WHERE condition so if the record was delete as you indicated no error is thrown since the WHERE condition was not met.

    Here is an example where the code was taken from the xsd file

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Claudio111 Tuesday, January 29, 2019 5:52 PM
    Thursday, January 24, 2019 7:54 PM