0

如何将数据添加到具有 5 列的 DataTable?

我正在使用 C++ (CLI)。

4

1 回答 1

2

来自MSDN

void AddRow(DataTable^ myTable){
    DataRowCollection^ rc; 
    DataRow^ myNewRow;
    // Create an array with three elements.
    Object rowVals[] = gcnew Object[3];
    rc = myTable->Rows;
    rowVals[0] = S"hello";
    rowVals[1] = S"world";
    rowVals[2] = S"two";
    // Add and return the new row.
    myNewRow = rc->Add(rowVals);
 }

您需要向 rowVals 添加两个新值,然后就可以不用了(PS 我通过眼睛将语法更改为 cli 语法,它可能无法完全按原样编译,但应该足以使用)

于 2009-04-20T10:54:37.273 回答