您好我正在使用C ++创建数据表,如下所示 当我尝试创建实例时,我收到编译时错误,因为无法为抽象类创建实例。在这里,我不会使用任何抽象的关键字。
#include "stdio.h"
#include "conio.h"
#using <mscorlib.dll>
using namespace System::Data;
using namespace System::ComponentModel;
using namespace System;
[Serializable]
public __gc class Table :public MarshalByValueComponent,public IListSource,public ISupportInitialize,public System::Runtime::Serialization:: ISerializable
{
public:
void MakeTable();
void main()
{
Table *s=new Table();
s->MakeTable();
Console::WriteLine("Hai");
printf("hello");
getch();
}
};
void Table::MakeTable()
{
DataSet* myDataSet;
// Create a new DataTable.
DataTable* myDataTable = new DataTable(S"ParentTable");
// Declare variables for DataColumn and DataRow objects.
DataColumn* myDataColumn;
DataRow* myDataRow;
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
myDataColumn = new DataColumn();
myDataColumn->DataType = System::Type::GetType(S"System.Int32");
myDataColumn->ColumnName = S"id";
myDataColumn->ReadOnly = true;
myDataColumn->Unique = true;
// Add the Column to the DataColumnCollection.
myDataTable->Columns->Add(myDataColumn);
// Create second column.
myDataColumn = new DataColumn();
myDataColumn->DataType = System::Type::GetType(S"System.String");
myDataColumn->ColumnName = S"ParentItem";
myDataColumn->AutoIncrement = false;
myDataColumn->Caption = S"ParentItem";
myDataColumn->ReadOnly = false;
myDataColumn->Unique = false;
// Add the column to the table.
myDataTable->Columns->Add(myDataColumn);
// Make the ID column the primary key column.
DataColumn* PrimaryKeyColumns[] = new DataColumn*[1];
PrimaryKeyColumns->Item[0] = myDataTable->Columns->Item[S"id"];
myDataTable->PrimaryKey = PrimaryKeyColumns;
// Instantiate the DataSet variable.
myDataSet = new DataSet();
// Add the new DataTable to the DataSet.
myDataSet->Tables->Add(myDataTable);
// Create three new DataRow objects and add them to the DataTable
for (int i = 0; i<= 2; i++){
myDataRow = myDataTable->NewRow();
myDataRow->Item[S"id"] = __box(i);
myDataRow->Item[S"ParentItem"] = String::Format( S"ParentItem {0}", __box(i));
myDataTable->Rows->Add(myDataRow);
}