如何在Temp Table中插入第二条记录?

时间:2021-06-30 01:57:44

In my form I used a Temporary Table in DataSource - with property TableType: InMemory .

在我的表单中,我在DataSource中使用了一个临时表 - 具有属性TableType:InMemory。

In My form I have a simple code,like this:

在我的表单中,我有一个简单的代码,如下所示:

public TableTmpTable insertRecords(String _param_I, string _param_II)
{ 
  TableTmpTable myInMemoryTable;

  myInMemoryTable.clear();
  myInMemoryTable.initValue();

  myInMemoryTable.Field_I =  _param_I;
  myInMemoryTable.Field_II = _param_II;

  myInMemoryTable.insert();

  return myInMemoryTable;
}

I need to call this method more than once.

我需要不止一次调用这个方法。

But, whenI call the method I lost my previous record. How can insert more record in InMemory table in different time?

但是,当我调用该方法时,我丢失了之前的记录。如何在不同时间在InMemory表中插入更多记录?

Thanks in advice!

谢谢你的建议!

2 个解决方案

#1


2  

Scope

范围

An InMemory table is instantiated when the first record is inserted. The instantiated InMemory table continues to exist only while a record buffer variable that references the table exists. The memory or disk space for the InMemory table is de-allocated as soon as the record buffer goes out of scope.

插入第一条记录时,将实例化InMemory表。只有在引用该表的记录缓冲区变量存在时,实例化的InMemory表才会继续存在。一旦记录缓冲区超出范围,就会取消分配InMemory表的内存或磁盘空间。

From MSDN, Temporary InMemory Tables

来自MSDN,临时InMemory表

What your code does is it creates a new instance of the table buffer each time the method is called. Instead, you need to use the table buffer of the form data source.

您的代码所做的是每次调用方法时都会创建表缓冲区的新实例。相反,您需要使用表单数据源的表缓冲区。

See also Temporary table as form data source and AX 2012: Using Temporary Table as Form’s Datasource

另请参见临时表作为表单数据源和AX 2012:将临时表用作表单的数据源

#2


0  

just split your method from one to two.

只需将您的方法从一个分为两个。

The first method will initialize your table and the second will insert your records.

第一种方法将初始化您的表,第二种方法将插入您的记录。

#1


2  

Scope

范围

An InMemory table is instantiated when the first record is inserted. The instantiated InMemory table continues to exist only while a record buffer variable that references the table exists. The memory or disk space for the InMemory table is de-allocated as soon as the record buffer goes out of scope.

插入第一条记录时,将实例化InMemory表。只有在引用该表的记录缓冲区变量存在时,实例化的InMemory表才会继续存在。一旦记录缓冲区超出范围,就会取消分配InMemory表的内存或磁盘空间。

From MSDN, Temporary InMemory Tables

来自MSDN,临时InMemory表

What your code does is it creates a new instance of the table buffer each time the method is called. Instead, you need to use the table buffer of the form data source.

您的代码所做的是每次调用方法时都会创建表缓冲区的新实例。相反,您需要使用表单数据源的表缓冲区。

See also Temporary table as form data source and AX 2012: Using Temporary Table as Form’s Datasource

另请参见临时表作为表单数据源和AX 2012:将临时表用作表单的数据源

#2


0  

just split your method from one to two.

只需将您的方法从一个分为两个。

The first method will initialize your table and the second will insert your records.

第一种方法将初始化您的表,第二种方法将插入您的记录。