Click here to Skip to main content
14,767,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends

I want to store the number of rows affected by the Insert Stored Procedure .

Based on the integer rows affected I want to form a decision branching using If -else.

Like if the rows affected is >0 then send the mail otherwise not.

But I am not able to store the number of rows being affected by the current datacontext object binded with Insert Stored Procedure.

For eg
<pre lang="c#">

<pre>if (objDataContext.USP_INSERT_ROWS(Parameters 1, Paramenters 2 ...Parameters n) == 0)
                 {
                     objDataContext.SubmitChanges();
                     ChangeSet cs = objDataContext.GetChangeSet();
                     
                     int rowsInserted = cs.Inserts.Count;
                     if (rowsInserted > 0)
                     {
                         lbMsg.Text = "Rows inserted Successfully " + rowsInserted + "rows Inserted";
                         
                         SendMail();
                     }
                     else
                     {
                         lbMsg.Text = "You have already sent  this request  " + rowsInserted";
                        
                     }

                     //SendMail();
                 }
                 else
                 {
                     Response.Write("<script>alert('Some Error')</script>");
                    
                 }





in all the occasions it goes into the else branch.
Posted

1 solution

Your get Changeset should be before you submit changes.

ChangeSet cs = objDataContext.GetChangeSet();
Console.Write("Total changes: {0}", cs);


But please note that it has side effects, such as inference of insert and delete operations that are usually performed at the time of SubmitChanges
   

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