返回受LINQ插入存储过程影响的行数 [英] Return Number of rows Affected by a Insert Stored Procedure with LINQ
问题描述
嗨朋友
我想存储受插入存储过程影响的行数。
基于受影响的整数行,我想使用If -else形成一个决策分支。
如果受影响的行是> 0,则发送邮件否则没有。
但是我无法存储受插入存储过程绑定的当前datacontext对象影响的行数。
例如
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>");
}
在进入else分支的所有场合。
in all the occasions it goes into the else branch.
推荐答案
你的变更集应该在你提交变更之前。
Your get Changeset should be before you submit changes.
ChangeSet cs = objDataContext.GetChangeSet();
Console.Write("Total changes: {0}", cs);
但是请注意,它有副作用例如,通常在SubmitChanges时执行的插入和删除操作的推断
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
这篇关于返回受LINQ插入存储过程影响的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!