#include "stdafx.h"
using namespace System;
using namespace System::Data;
void main()
{
DataSet^ myDataSet = gcnew DataSet("Game Data");
myDataSet->Tables->Add("Player");
myDataSet->Tables->Add("Score");
DataTable^ playerTable = myDataSet->Tables["Player"];
DataColumn^ firstNameColumn1 = playerTable->Columns->Add("First Name",String::typeid);
DataColumn^ lastNameColumn1 = playerTable->Columns->Add("Last Name",String::typeid);
playerTable->Columns->Add("Email", String::typeid);
array<DataColumn^>^ primaryKey = {firstNameColumn1, lastNameColumn1};
playerTable->Constraints->Add("PlayerPK", primaryKey, true);
// Add columns to 2nd table
DataTable^ ScoreTable = myDataSet->Tables["Score"];
DataColumn^ firstNameColumn2 = ScoreTable->Columns->Add("First Name",String::typeid);
DataColumn^ lastNameColumn2 = ScoreTable->Columns->Add("Last Name",String::typeid);
ScoreTable->Columns->Add("Points", int::typeid);
array<DataColumn^>^ foreignKey = {firstNameColumn2, lastNameColumn2};
ScoreTable->Constraints->Add("PlayerFK", primaryKey, foreignKey);
// (Same as establish a data relation)
//myDataSet->Relations->Add("Player-Score", PrimaryKey, ForeignKey);
}
|