// clrTest1.cpp: 主项目文件。 #include "stdafx.h" using namespace System;
using namespace System::Data; int main(array<System::String ^> ^args)
{
DataTable^ dtable = gcnew DataTable("myTable");
DataColumn^ column;
//col 1
column = gcnew DataColumn("begin_time",System::DateTime::typeid);
dtable->Columns->Add(column);
// col 2
column = gcnew DataColumn("name", String::typeid);
dtable->Columns->Add(column);
// col 3
column = gcnew DataColumn("dscrib", String::typeid);
dtable->Columns->Add(column);
//primary key
array<DataColumn^>^ Keys = gcnew array<DataColumn^>();
Keys[] = dtable->Columns["name"];
Keys[] = dtable->Columns["dscrib"];
dtable->PrimaryKey = Keys;
//dataset
DataSet^ dset = gcnew DataSet();
dset->Tables->Add(dtable);
//add dataRow
String^ str = Console::ReadLine();
int lines ;
try
{
lines = Convert::ToInt32(str);
}
catch (...){}
DataRow^ row ;
for(int i = ; i < lines ; i ++)
{
row = dtable->NewRow();
DateTime^ dtime = DateTime::Now;
dtime = dtime->AddHours(i);
row["begin_time"] = dtime ;
row["name"] = "John_"+(i+);
row["dscrib"] = "it_is_row_"+(i+);
dtable->Rows->Add(row);
}
//out-put
for(int i = ; i < dtable->Rows->Count; i ++)
{
row = dtable->Rows[i];
for(int j = ; j < dtable->Columns->Count; j ++)
{
Console::WriteLine(row[j]+"\t");
}
Console::WriteLine();
}
Console::ReadKey();
return ;
}