如何使用表适配器获取插入影响的行数

时间:2011-12-07 07:54:21

标签: c# asp.net visual-studio

如何使用表适配器获取插入影响的行数。?

我有这个示例类

public void InsertLeave(DateTime sd, DateTime ed,string reason, string type, int empid)
{
    Adapter.InsertLeave(sd, ed, reason, type, empid);
}

返回void,但我希望通过此插入返回受影响行的int。

2 个答案:

答案 0 :(得分:0)

你能复制并粘贴Adapter.InsertLeave方法的方法签名和正文吗?

如果通过向导创建了Adapter.InsertLeave的ExecuteMode,则它将设置为Scalar / Non Query,它将返回一个int值;一个返回受影响的行数,另一个返回插入行的id。

答案 1 :(得分:0)

如果您有权更改/编辑方法InsertLeave,则添加另一个输出参数并相应地获取。

public void InsertLeave(DateTime sd, DateTime ed,string reason, string type, int empid)
{
    int rowsEffected = 0;
    Adapter.InsertLeave(sd, ed, reason, type, empid, out rowsEffected);
    //Now you've available number of rows effected into `rowsEffected`
}

OR

将返回类型void更改为方法InsertLeave

的int

由于