DataSet不保存数据

时间:2017-03-04 00:41:47

标签: c#

这是我第一次使用DataSet。以下是我的代码

var transactionSet = new ModelExecutionContext()
        {
            TransactionSet = new DataSet()
            {
                Tables = { new DataTable()
                {
                    TableName = "transaction_history"
                }
                }
            }
        };

        transactionSet.TransactionSet.Tables["transaction_history"].Columns.Add().ColumnName = "retailer_reference_id";
        var retailerReferenceIdRow = transactionSet.TransactionSet.Tables["transaction_history"].NewRow();
        retailerReferenceIdRow["retailer_reference_id"] = 8;

        transactionSet.TransactionSet.AcceptChanges();

我在具有数据集的类中测试方法。我试图模拟这些数据集。我认为transactionSet.TransactionSet.AcceptChanges();会将更改保存到DataSet,但在执行中,我得到context?.TransactionSet?.Tables["transaction_history"]?.Rows.Count = 0

我的代码有什么不对吗?

1 个答案:

答案 0 :(得分:1)

创建行对象后,需要在表中添加行。

df <- data.frame(ID=c("id1", "id1","id2", "id2","id3","id3","id3"),
                 day=c("01/02/2008","01/02/2008","10/02/2009","08/03/2009","11/08/2007","11/08/2007","11/08/2008"),
                 it =c("ul","tr","cb","ul","ul","tc","tr"))