C# SqlDataAdapter在成功插入期间未触发RowUpdate或RowUpdate

C# SqlDataAdapter在成功插入期间未触发RowUpdate或RowUpdate,c#,sql,sqlconnection,sqldataadapter,datatableadapters,C#,Sql,Sqlconnection,Sqldataadapter,Datatableadapters,我有以下代码: DataSet dataSet = new DataSet(); bool result; using (SqlConnection connection = new SqlConnection(command.Connection.ConnectionString)) { connection.Open();

我有以下代码:

DataSet dataSet = new DataSet();
                bool result;
                using (SqlConnection connection = new SqlConnection(command.Connection.ConnectionString))
            {
            connection.Open();                             

            SqlDataAdapter adapter = new SqlDataAdapter(command);
            SqlCommandBuilder builder = new SqlCommandBuilder(adapter);

            adapter.RowUpdated += OnRowUpdated;
            adapter.RowUpdating += AdapterOnRowUpdating;


            adapter.Fill(dataSet);

            // Code to modify data in the DataSet here.
            // Without the SqlCommandBuilder, this line would fail.
            adapter.UpdateCommand = builder.GetUpdateCommand();

            int i = adapter.Update(dataSet);
            result = i > 0;
        }
        return result;
假设此代码获取我的SqlCommand对象并将其提交给SqlDataAdapter的更新方法。SqlCommand可以是使用adapter.UPDATE()方法执行的INSERT、UPDATE或DELETE命令

命令执行成功,但adapter.Update()方法返回0行。我已经检查了数据库,我可以看到它是成功的。RowUpdated和RowsUpdating事件也不会触发。我不知道发生了什么事。请帮忙

先谢谢你

编辑:

 public void OnRowUpdated(object sender, SqlRowUpdatedEventArgs sqlRowUpdatedEventArgs)
        {
            switch (sqlRowUpdatedEventArgs.StatementType)
            {
                case StatementType.Insert:
                case StatementType.Update:
                case StatementType.Delete:
                case StatementType.Batch:
                    if (sqlRowUpdatedEventArgs.Status != UpdateStatus.ErrorsOccurred)
                        SqlReporting.LogSqlCommand(sqlRowUpdatedEventArgs.Command);
                    break;
            }
        }
编辑: Im使用以下查询插入:

INSERT INTO Users
                         (Username, Firstname, Lastname, RoleId, ReceiveRoleAlerts, StatusId, Password, Fingerprint, AuthenticityCheck, CreatedByUserId, CreationDate, ModifiedByUserId, 
                         ModificationDate)
SELECT        @Username AS Expr1, @Firstname AS Expr2, @Lastname AS Expr3, @RoleId AS Expr4, @ReceiveRoleAlerts AS Expr5, @StatusId AS Expr6, @Password AS Expr7, 
                         @Fingerprint AS Expr8, @AuthenticityCheck AS Expr9, @CreatedByUserId AS Expr10, @CreationDate AS Expr11, @ModifiedByUserId AS Expr12, 
                         @ModificationDate AS Expr13
WHERE        (NOT EXISTS
                             (SELECT        Username, Firstname, Lastname, RoleId, ReceiveRoleAlerts, StatusId, Password, Fingerprint, AuthenticityCheck, CreatedByUserId, CreationDate, 
                                                         ModifiedByUserId, ModificationDate
                               FROM            Users AS Users_1
                               WHERE        (Username = @Username)));
使用

而不是

adapter.RowUpdated += OnRowUpdated;
adapter.RowUpdating += AdapterOnRowUpdating;

谢谢你的快速回复。我已经修改了代码以反映您的建议,但不幸的是,它仍然是同一个问题。插入成功,但未启动任何事件,即使插入成功,adapter.Update()仍返回0。我使用的是sql server 2008 express。我现在发布实现
adapter.RowUpdated += OnRowUpdated;
adapter.RowUpdating += AdapterOnRowUpdating;