Материал из .Net Framework эксперт
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Using CommandBuilder
#include "stdafx.h"
using namespace System;
using namespace System::Data;
using namespace System::Data::OleDb;
void main()
{
OleDbConnection^ myConnection = nullptr;
myConnection = gcnew OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Music.mdb");
myConnection->Open();
OleDbDataAdapter^ dataAdapter = gcnew OleDbDataAdapter("SELECT * FROM Music", myConnection);
OleDbCommandBuilder^ commandBuilder = gcnew OleDbCommandBuilder(dataAdapter);
dataAdapter->UpdateCommand = commandBuilder->GetUpdateCommand();
dataAdapter->DeleteCommand = commandBuilder->GetDeleteCommand();
dataAdapter->InsertCommand = commandBuilder->GetInsertCommand();
DataSet^ myDataSet = gcnew DataSet();
dataAdapter->MissingSchemaAction = MissingSchemaAction::AddWithKey;
dataAdapter->Fill(myDataSet);
DataTable^ myTable = myDataSet->Tables[0];
DataRow^ row = myTable->Rows->Find("Consequential2");
if ( row != nullptr )
row->Delete();
row = myTable->Rows->Find("S");
if ( row != nullptr )
row["Title"] = "S";
row = myTable->NewRow();
row["Title"] = "TT";
row["GenreName"] = "Classical";
row["Duration"] = "4:20";
myTable->Rows->Add(row);
dataAdapter->Update(myDataSet);
myConnection->Close();
}