ExecuteNonQuery is not returning no of rows affected (Oracle Provider)

Hi ,

I am using Oracle provider for data access.But the ExecuteNonQuery  of Oracle command is not returning the no of rows affected properly.Its always returning 1 while deleting records.

(I tried to delete a junk id from database,at the time also its returning 1)

Could you pls help me to sort it out.

This is the snippet which i am using,

Dim Cmd As OracleCommand

Dim retVal As Integer

Cmd = New OracleCommand

'Custom function for attaching connection and transaction with command

PrepareCommand(Cmd, Con, Trans, CommandType, commandText, commandParameters)

retVal = Cmd.ExecuteNonQuery()

Cmd.Dispose()

 

Prasanth



Answer this question

ExecuteNonQuery is not returning no of rows affected (Oracle Provider)

  • Nico_Shao

    Hi,

    I am using stored procedure ,not embedded queries.Could you please try with stored procedures.

    Prasanth


  • luoqi

    I am also facing the similar problem.
    ExecuteNonQuery() is not returning No of rows affected correctly when the command type is stored procedure. I am using Entriprise Library - January 2006 for Data Access.

    ExecuteNonQuery() when call on a command (type stored procedure) talways returns 1, no matter how many rows are affected inside the procedure.

    Please suggest.

    Sishir

  • Craig Harris

    Here is a small code sample. I ran this and I get back the correct return value each time from ExecuteNonQuery(). The Last stmt (delete) returns 3.

    using System.Data;
    using System.Data.OracleClient;
    using System;

    namespace DataViewer.Repro {

    public class Repro {

    public static int Main(string[] args) {
    OracleConnection oracleconnection3 = new OracleConnection("data source=MyServer; user id=me; password=me;");
    oracleconnection3.Open();
    OracleCommand oraclecommand1 = oracleconnection3.CreateCommand();
    oraclecommand1.CommandText = "create table siraj (c1 float, c2 char)";
    Int32 int321 = oraclecommand1.ExecuteNonQuery(); // returns 0
    oraclecommand1.CommandText = "insert into siraj values (11, 'a')";
    Int32 int322 = oraclecommand1.ExecuteNonQuery(); // returns 1
    oraclecommand1.CommandText = "insert into siraj values (12, 'a')";
    Int32 int323 = oraclecommand1.ExecuteNonQuery(); // returns 1
    oraclecommand1.CommandText = "\ninsert into siraj values (13, 'a')";
    Int32 int324 = oraclecommand1.ExecuteNonQuery(); // returns 1
    oraclecommand1.CommandText = "insert into siraj values (21, 'b')";
    Int32 int325 = oraclecommand1.ExecuteNonQuery(); // returns 1
    oraclecommand1.CommandText = "select * from siraj";
    Int32 int326 = oraclecommand1.ExecuteNonQuery(); // returns -1
    oraclecommand1.CommandText = "delete from siraj where c2 = 'a'";
    Int32 int327 = oraclecommand1.ExecuteNonQuery(); // returns 3
    return 1;
    }
    }
    }



  • CBrookes86

    Hi,

    if you use "set nocount on" option in sp you can't get affected rows. also executenonquery returns affected row count.


  • ExecuteNonQuery is not returning no of rows affected (Oracle Provider)