Visual C++ .NET/Database ADO.net/DataView

Материал из .Net Framework эксперт
Версия от 12:06, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

DataView Setting

 
#include "stdafx.h"
using namespace System;
using namespace System::Data;
void main()
{
    DataSet^ myDataSet = gcnew DataSet("GData");
    myDataSet->ReadXml("schema.xml");
    DataTable^ playerTable = myDataSet->Tables["Player"];
    for ( int i = 0; i < playerTable->Rows->Count; i++ )
        Console::WriteLine("Player {0}: {1} {2}",i, playerTable->Rows[i]["First_Name"],playerTable->Rows[i]["Last_Name"]);
    DataViewSetting^ viewSettings = myDataSet->DefaultViewManager->DataViewSettings["Player"];
    viewSettings->RowFilter = "Last_Name="F"";
    viewSettings->Sort = "First_Name DESC";
    Console::WriteLine();
    Console::WriteLine("{0} rows in the view",playerTable->DefaultView->Count);
    for ( int i = 0; i < playerTable->DefaultView->Count; i++ )
        Console::WriteLine("Player {0}: {1} {2}", i,
        playerTable->DefaultView[i]["First_Name"],
        playerTable->DefaultView[i]["Last_Name"]);
}


Using DataView

 
#include "stdafx.h"
using namespace System;
using namespace System::Data;
void main()
{
    DataSet^ myDataSet = gcnew DataSet("Game_Data");
    myDataSet->ReadXml("schema.xml");
    DataTable^ playerTable = myDataSet->Tables["Player"];
    for ( int i = 0; i < playerTable->Rows->Count; i++ )
        Console::WriteLine("Player {0}: {1} {2}",
        i, playerTable->Rows[i]["First_Name"],
        playerTable->Rows[i]["Last_Name"]);
    DataView^ myView = gcnew DataView(playerTable, "Last_Name="F"","First_Name DESC", DataViewRowState::CurrentRows);
    Console::WriteLine();
    Console::WriteLine("{0} rows in the view", myView->Count);
    for ( int i = 0; i < myView->Count; i++ )
        Console::WriteLine("Player {0}: {1} {2}", i,myView[i]["First_Name"],myView[i]["Last_Name"]);
}