次の一覧は、推奨されるハードウェア、ソフトウェアです、ネットワーク インフラストラクチャ、および必要な service pack:
次のいずれか: Microsoft Windows 2000 ProfessionalMicrosoft Windows 2000 Server、Microsoft Windows 2000 Server では、高度なかMicrosoft Windows NT 4.0 サーバー
次のいずれか: Microsoft SQL Server version 7.0 では、Microsoft SQL Server 2000、または Microsoft データ エンジン (MSDE) の PUBS サンプルデータベースのインストール適切なアクセス許可、ユーザー Id とパスワードの値を指定します。
マイクロソフトの Visual Studio。NET またはマイクロソフトの Visual Studio 2005
SqlConnection *objConn;
String *sConnectionString;
sConnectionString = "Password=StrongPassword;User ID=UserName;Initial Catalog=pubs;Data Source=(local)";
objConn = new SqlConnection(sConnectionString);
objConn->Open();
// Create an instance of a DataAdapter.
SqlDataAdapter* daAuthors = new SqlDataAdapter("Select * From Authors", objConn);
// Create an instance of a DataSet, and retrieve data from the Authors table.
DataSet* dsPubs = new DataSet("Pubs");
daAuthors->FillSchema(dsPubs,SchemaType::Source, "Authors");
daAuthors->Fill(dsPubs,"Authors");
メモ 共通言語ランタイム サポートのコンパイラ オプションを追加する必要があります (//clr:oldsyntax) 正常に上記のコード サンプルをコンパイルする Visual C 2005 で。Visual C 2005 で、共通言語ランタイム サポート コンパイラ オプションを追加するには、次の手順を実行します。
// BEGIN ADD CODE
// Create a new instance of a DataTable.
DataTable* tblAuthors = dsPubs->Tables->Item["Authors"];
// Obtain a new DataRow object from the DataTable.
DataRow* drCurrent = tblAuthors->NewRow();
// Set the DataRow field values as necessary.
drCurrent->set_Item("au_id",new String("993-21-3427"));
drCurrent->set_Item("au_fname",new String("George"));
drCurrent->set_Item("au_lname",new String("Johnson"));
drCurrent->set_Item("phone",new String("800 226-0752"));
drCurrent->set_Item("address", new String ("1956 Arlington Pl."));
drCurrent->set_Item("city", new String("Winnipeg"));
drCurrent->set_Item("state", new String("MB"));
drCurrent->set_Item("contract",__box(1));
// Pass that new object into the Add method of the DataTable.
tblAuthors->Rows->Add(drCurrent);
Console::WriteLine("Add was successful, Click any key to continue!!");
Console::ReadLine();
// END ADD CODE
// BEGIN SEND CHANGES TO SQL SERVER
SqlCommandBuilder* objCommandBuilder = new SqlCommandBuilder(daAuthors);
daAuthors->Update(dsPubs, "Authors");
Console::WriteLine("SQL Server updated successfully, Check Server explorer to see changes");
Console::ReadLine();
// END SEND CHANGES TO SQL SERVER
//BEGIN DELETE CODE
drCurrent = tblAuthors->Rows->Find(new String("993-21-3427"));
drCurrent->Delete();
Console::WriteLine("Record deleted successfully, Click any key to continue!!");
Console::ReadLine();
//END DELETE CODE
SQL のレコードを削除するサーバーに変更を送信すること以前のバージョンを追加します。
手順 9 に、コードの後次のコードを貼り付けます。
// CLEAN UP SQL SERVER
daAuthors->Update(dsPubs, "Authors");
Console::WriteLine("SQL Server updated successfully, Check Server explorer to see changes");
Console::ReadLine();
objConn->Close ();
// This is the main project file for VC++ application project
// generated using an Application Wizard.
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.Dll>
#using <System.Data.Dll>
#using <System.Xml.dll>
#include <tchar.h>
using namespace System;
using namespace System::Xml;
using namespace System::Data;
using namespace System::Data::SqlClient;
// This is the entry point for this application
int _tmain(void)
{
SqlConnection *objConn;
try
{
String *sConnectionString;
sConnectionString = "Password=StrongPassword;User ID=UserName;Initial Catalog=pubs;Data Source=(local)";
objConn = new SqlConnection(sConnectionString);
objConn->Open();
// Create an instance of a DataAdapter.
SqlDataAdapter* daAuthors = new SqlDataAdapter("Select * From Authors", objConn);
// Create an instance of a DataSet, and retrieve data from the Authors table.
DataSet* dsPubs = new DataSet("Pubs");
daAuthors->FillSchema(dsPubs,SchemaType::Source, "Authors");
daAuthors->Fill(dsPubs,"Authors");
// BEGIN ADD CODE
// Create a new instance of a DataTable.
DataTable* tblAuthors = dsPubs->Tables->Item["Authors"];
// Obtain a new DataRow object from the DataTable.
DataRow* drCurrent = tblAuthors->NewRow();
// Set the DataRow field values as necessary.
drCurrent->set_Item("au_id",new String("993-21-3427"));
drCurrent->set_Item("au_fname",new String("George"));
drCurrent->set_Item("au_lname",new String("Johnson"));
drCurrent->set_Item("phone",new String("800 226-0752"));
drCurrent->set_Item("address", new String ("1956 Arlington Pl."));
drCurrent->set_Item("city", new String("Winnipeg"));
drCurrent->set_Item("state", new String("MB"));
drCurrent->set_Item("contract",__box(1));
// Pass that new object into the Add method of the DataTable.
tblAuthors->Rows->Add(drCurrent);
Console::WriteLine("Add was successful, Click any key to continue!!");
Console::ReadLine();
// END ADD CODE
// BEGIN EDIT CODE
drCurrent = tblAuthors->Rows->Find(new String("213-46-8915"));
drCurrent->BeginEdit();
drCurrent->set_Item("phone",String::Concat(S"342",(static_cast<String *>(drCurrent->Item["phone"]))->Substring(3)));
drCurrent->EndEdit ();
Console::WriteLine("Record edited successfully, Click any key to continue!!");
Console::ReadLine();
// END EDIT CODE
// BEGIN SEND CHANGES TO SQL SERVER
SqlCommandBuilder* objCommandBuilder = new SqlCommandBuilder(daAuthors);
daAuthors->Update(dsPubs, "Authors");
Console::WriteLine("SQL Server updated successfully, Check Server explorer to see changes");
Console::ReadLine();
// END SEND CHANGES TO SQL SERVER
//BEGIN DELETE CODE
drCurrent = tblAuthors->Rows->Find(new String("993-21-3427"));
drCurrent->Delete();
Console::WriteLine("SRecord deleted successfully, Click any key to continue!!");
Console::ReadLine();
//END DELETE CODE
// CLEAN UP SQL SERVER
daAuthors->Update(dsPubs, "Authors");
Console::WriteLine("SQL Server updated successfully, Check Server explorer to see changes");
Console::ReadLine();
}
catch (Exception* ex)
{
Console::WriteLine (ex->Message );
}
__finally
{
objConn->Close ();
}
}
Microsoft Knowledge Base の免責: Microsoft Knowledge Baseに含まれている情報は、いかなる保証もない現状ベースで提供されるものです。Microsoft Corporation及びその関連会社は、市場性および特定の目的への適合性を含めて、明示的にも黙示的にも、一切の保証をいたしません。さらに、Microsoft Corporation及びその関連会社は、本文書に含まれている情報の使用及び使用結果につき、正確性、真実性等、いかなる表明・保証も行ないません。Microsoft Corporation、その関連会社及びこれらの権限ある代理人による口頭または書面による一切の情報提供またはアドバイスは、保証を意味するものではなく、かつ上記免責条項の範囲を狭めるものではありません。Microsoft Corporation、その関連会社 及びこれらの者の供給者は、直接的、間接的、偶発的、結果的損害、逸失利益、懲罰的損害、または特別損害を含む全ての損害に対して、状況のいかんを問わず一切責任を負いません。(Microsoft Corporation、その関連会社 またはこれらの者の供給者がかかる損害の発生可能性を了知している場合を含みます。) 結果的損害または偶発的損害に対する責任の免除または制限を認めていない地域においては、上記制限が適用されない場合があります。なお、本文書においては、文書の体裁上の都合により製品名の表記において商標登録表示、その他の商標表示を省略している場合がありますので、予めご了解ください。