none
Query has inserted data or not RRS feed

  • Question

  • Dear All,

    i am interested to check weather the query has inserted data in a table or not , i have to send an email if the data is inserted and its a console application.


    if the post helpful please mark it right else feel free to correct me
    Saturday, May 29, 2010 8:01 AM

Answers

  • This might depend on the specific database server you are using.

    Are you using ExecuteNonQuery by passing in a command containing the SQL statement you want to run?  If so, check out the return value of this method as it is documented "The number of rows affected."

    http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.executenonquery.aspx

    If a stored procedure is involved, what you really should do is modify that stored procedure so that it determines the number and puts it in an OUTPUT parameter.  How to do this depends on the database vendor.

     

    • Marked as answer by uahmed Saturday, May 29, 2010 7:43 PM
    Saturday, May 29, 2010 6:00 PM

All replies

  • This might depend on the specific database server you are using.

    Are you using ExecuteNonQuery by passing in a command containing the SQL statement you want to run?  If so, check out the return value of this method as it is documented "The number of rows affected."

    http://msdn.microsoft.com/en-us/library/system.data.common.dbcommand.executenonquery.aspx

    If a stored procedure is involved, what you really should do is modify that stored procedure so that it determines the number and puts it in an OUTPUT parameter.  How to do this depends on the database vendor.

     

    • Marked as answer by uahmed Saturday, May 29, 2010 7:43 PM
    Saturday, May 29, 2010 6:00 PM
  • I am using ExecuteNonQuery .

    Code :

                        int rowseffect;

                        rowseffect = nonqueryCommand.ExecuteNonQuery();
                        Console.WriteLine("Rows effected are "+ rowseffect);
    if the post helpful please mark it right else feel free to correct me
    Saturday, May 29, 2010 7:45 PM