ExecuteNonQuery does not throw an exception on insert

I am using OracleCommand.ExecuteNonQuery () to insert into a table. Everything works fine, but sometimes records are not inserted. Is it possible that ExecuteNonQuery () does not insert a record, nor does it throw an exception?

I do not use stored procedures. I do not use a transaction. I am logging any exception that is called by ExecuteNonQuery (), but apparently no exception has been thrown ... I also do not check the return value of ExecuteNonQuery (). But is it possible that ExecuteNonQuery returns a different value than 1 if the insert was successful?

+3
source share
6 answers

. ExecuteNonQuery , . , 0. , . E.x.: , ..

+3

, - , :

try
{
   DoSomethingOnTheDbThatMightThrowAnException();
}
catch(Exception ex)
{
   // Do nothing, thus swallowing the exception
}

ExecuteNonQuery(). 0, .

+2

.

, ?

+1

" , ". / , , . / .

+1

.

, DBNull.Value gridviewcell proc .

- :

if(cell.Value != DBNull.Value && cell.Value != null)  
{    
    //add the parameter to the Command object  
}

, , , Convert.ToDecimal NumberFormatException .

NumberFormatException, cmd.ExecuteNonQuery().

, , , ExecuteNonQuery().

, :

if(cell.Value != DBNull.Value &&
!string.IsNullOrEmpty(cell.Value.ToString()))
{
   //Create and Add the parameter
}
0

Maybe ExecuteNonQuery () throws an exception that does not fall into your try-catch block. Check your Windows event log to be sure; An AccessViolationException may occur due to a failure of one of your drivers, and such an exception is usually not caught in managed code from .NET 4.0 onwards. The solution is described on this link .

0
source

Source: https://habr.com/ru/post/1724503/


All Articles