当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Datatable.GetErrors returning incorrect datarows

问题描述:

I am using a datatable to insert records in the database, making use of the Data Block of the Enterprise Library.

As you will see in the code below, I issue a UpdateDataSet on the dataset and then look for errors in the DataTable, extracting the offending datarows. I have to generate a report on these erroneous records.

For testing I have added one row which will conform to the database and get inserted, added another which violates a FK constraint.

 DbCommand command = _database.GetStoredProcCommand("SP_Simple_Insert");

_database.AddInParameter(command, "JobID", DbType.Int32, "JobID", DataRowVersion.Current);

...

...

...

int rowsaffected = _database.UpdateDataSet(dataSet, tableName, command, null, null, UpdateBehavior.Continue, batchSize); // batchsize is 1000

LogMessage("SaveBatch", string.Format("BatchCount: {0}, AffectedRows: {1}", dataSet.Tables[0].Rows.Count, rowsaffected), Level.Info);

if (dataSet.Tables[tableName].HasErrors)

{

DataRow[] rows = dataSet.Tables[tableName].GetErrors();

LogMessage("SaveBatch", string.Format("Errors: {0}", rows.Length), Level.Debug);

}

When I look at the Datarow returned from the GetErrors method, it is actually the one which got inserted in the database.

When I have just the erroneous row in the dataset, it returns the correct row in the errors.

I am not certain if this because of the Enterprise library or something else. One thing is for sure this is not how it should be.

分享给朋友:
您可能感兴趣的文章:
随机阅读: