Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I want to know how to know the number of rows affected in UPDATE/DELETE/INSERT Oracle query in asp.net.net mvc program

What I have tried:

ExuteNonQuery ===> return -1
I used also sql%rowcount but doesn't return anything
Posted
Updated 30-Apr-18 3:59am

1 solution

I am not sure how you are preparing the query? are you using sqlcommand ?. you did not given your code, I can't help you correctly. But look into this link[^], it will help you.



using (SqlConnection con = new SqlConnection(constring))
{
    using (SqlCommand cmd = new SqlCommand("UPDATE Persons SET City = @City WHERE Name = @Name", con))
    {
        cmd.CommandType = CommandType.Text;
        cmd.Parameters.AddWithValue("@Name", name);
        cmd.Parameters.AddWithValue("@City", city);
        con.Open();
        int rowsAffected = cmd.ExecuteNonQuery();
        con.Close();
    }
}


--RA
 
Share this answer
 
v2
Comments
aida1986 30-Apr-18 10:03am    
The problem is with Oracle database ExuteNonQuery doesn't return the number of rows but it is always -1
Rajesh Anuhya 30-Apr-18 10:05am    
Have you checked the link I provided? , if possible can you share your code?
--RA
aida1986 30-Apr-18 10:09am    
   string RTmpSys = string.Empty;
             RTmpSys = "DELETE FROM HPRELEV "
             + "WHERE HPRELEV.EXE_COD = :EXE_COD "
           + "AND HPRELEV.MOI_COD = :MOI_COD "
           + "AND HPRELEV.TPA_COD = :TPA_COD "
          + "AND HPRELEV.EMP_MAT IN (SELECT EMPLOYE.EMP_MAT FROM EMPLOYE WHERE " + OrdEmp
        + " ); ";
aida1986 30-Apr-18 10:10am    
I want to return the number of rows deleted in Oracle Database
Rajesh Anuhya 30-Apr-18 10:11am    
I don't need your query, I want to know, how you are using the SQLCommand, Please check my below soluation example and, try to implement same

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900