????? ????? ???? DataSet ?? ????? ?????? ???????? .NET Visual C++ ?? Visual C++ 2005

?????? ????????? ?????? ?????????
???? ???????: 818779 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ??? ????? ????? DataSet ?????? ?? ????? ??????? ????? ?????? ???? ?? ???? ?? ????? ?????? ??? ???????? ??? ????? ????????? ?? ?????? DataSet. ???????? DataSet ?? ???????? ?? ??????? ???? ???? ???????? ??????? ???? ????? ???????? ???? ???? ??? ????? ?? ?????? ??? ???????? ?? Microsoft .NET Framework.


??????? ????

???????

???? ??????? ??????? ??????? ?????? ??? ????? ?????? ???????? ?????? ? ??? ??????? ???? ??? ?? ???? ????:
  • ????? Microsoft Windows 2000 Professional ?? ???? ??????? Microsoft Windows 2000 Server ?? ???? ??????? Microsoft Windows 2000 Server ?? Microsoft Windows NT 4.0 Server
  • Microsoft SQL Server 7.0 ?? Microsoft SQL Server 2000 ?? Microsoft Engine ?????? ?? ????? ?????? ????? Pubs ?????
  • Microsoft Visual Studio .NET ?? Microsoft Visual Studio 2005
????? ??? ??????? ??? ??????? ??? ???????? ???????:
  • ??????? ????? ????????
  • Microsoft SQL Server


????? DataSet

???????? ?????? ?? ???????? ?? ????? ????? System.Data ????? ??????? ????? ????? ?????? ?? ????? ??????? ??? ?? ??? ??????? ???? ?? ????? ?? ???? DataSet. DataSet ???? ?? ??? ???????. ????? ??? ????? ???????? ?? ??? ??????? ????? ????? ?????? ??? ???? ????? ?????? ?? ???????? ?? ????? ?????? ?????????? ???? ????? ??? ???? ????????? ?? ???????.

?????? ???????? ?? ????? ?????? ??? DataSet ???? ??????? ???????:
  1. ??? ????? Visual Studio .NET ?? Visual Studio 2005.
  2. ????? ????? ??? ?????? C++ ???? ?? Visual C++ .NET 2002 ? ?? ????? ????? ???? ???? ???? ?? Visual C++ .NET 2003 ?? ????? ????? ???? ?????? CLR ???? ?? Visual C++ 2005. ??? ??????? MyApplication ?? ???? ??? ?????.
  3. ?? ?????? ????????? ???????? ??????? ??? MyApplication.cpp ?????.

    ???? ??? ??? ????? ???? ??? ????? ????? System.Dll ????? ????? System.Xml ?????? System.Data.
    #using <System.Dll>
    #using <System.Data.Dll>
    #using <System.Xml.Dll>
    
  4. ?????? ????? USING ??? ?? ????? ????? ?????? ????? ????? System.Data ????? ????? System.Xml ????? ????? System.Collections ????? ????? System.Data.SqlClient ???? ?? ???? ????? ????????? ?? ?????? ??????? ??? ???? ??? ?? ????????? ???????? ?????? ??. ??? ??????? ??? ???????? ??? ?? ?????? ?????????.
    using namespace System;
    using namespace System::Data;
    using namespace System::Xml;
    using namespace System::Collections;
    using namespace System::Data::SqlClient;
    
  5. ??? ???????? ?? ????? ???????? ??? DataSet.

    ?????? ????? ??? ???? ????? ????? ????? ??????. ????? ??? ???? System.Data.SqlClient.SqlCommand ????? ?????. ????? ??????? ?? ????????? ???????? ??? ??????? ???? ???? ?????? SQL Server ??????? ??? ????????? ?????? (????????? ??? ??? ????? ????????? ????????). ??? ????? ??? ??????? ??????? ??? ?? ????? ?????. ??? ????? ?????? SqlConnection ??????? ????? ??? ?????? ??? ????? ?????? ????? ???????? ???????. objConn
    SqlConnection* objConn;
    String* sConnectionString;
    sConnectionString = "Password=myPassword;User ID=myUserID;Initial Catalog=pubs;Data Source=(local)";
    
    objConn = new SqlConnection(sConnectionString);
    objConn->Open();
    
  6. ????? ???? DataAdapter ???? ?????? ??? ????? ???????? ?????? DataSet. ????? ????? SQL Server ?? ??? ??? ?? ??? ???????? ???????? ???????? ???? ?? ?????? ????? DataAdapter. ?????? ????? ?????? SQL ???? ???? ???????? ??????? ?? ???? "???????" ?? ????? ?????? Pubs.
    SqlDataAdapter* daAuthors = new SqlDataAdapter("Select * From Authors", objConn);
    
  7. ???? ?????? ?? ?? ?????? ???? ?? DataSet ??????.

    ??? ?????? ????? ??? ????? ??? DataSet ??????? ??? ?? ????? ?? ????? ????? ??? ??????. ?? ????? ????? ??? ????? ???????.
    DataSet* dsPubs = new DataSet("Pubs");
  8. ????? FillSchema ??????? ????? ????? ?????? ????? ????????.

    ???? ????? SqlDataAdapter ??????? "?" ????? "?????" ? "????? FillSchema ???????? ????? ????? ??? ????????. ??? ????? ????? ??????? ??? DataSet. ????? ??????? ????? ???????? ????? ?? ????? FillSchema ?????? ???? ?????? ????? ?????? ??? ???? ???? (??? ????? ????? ???????? ???????? ???????). daAuthors
    daAuthors->FillSchema(dsPubs,SchemaType::Source, "Authors");
    daAuthors->Fill(dsPubs,"Authors");
    

    ??? ??? ?????? ??? ????? ? ????? ??? ????? ?????? ??????? ???????? ???? ??? ?? ???? ???? ???? ????? ??????? ?????? ????????. ?? ???? ????? ??????? ?????? ??????? ??????? ???????. ?????? ??? ?????? ????????? ????? ????? ??????? MissingSchemaAction ?????? DataAdapter ??? MissingSchemaAction.AddWithKey. ??? ?????? ?????? ????? ??????? ??????? ???????? ??? ??????? ????????. daAuthors
    daAuthors->MissingSchemaAction = MissingSchemaAction::AddWithKey;
    daAuthors->Fill(dsPubs,"Authors");
    
    ???????? ????? ???? ????? DataTable ????? ?? ???????? ????? DataSet. ??? ??? ?????? ??? ???? ?? ????????? FillSchema ?? ??? ????? ????? ??????? ??? ????? ??? ?????? ??? ???? ???? ???? ?????.
    DataTable* tblAuthors = dsPubs->Tables->Item["Authors"];
    
  9. ?????? ?????? GetEnumerator ?????? ??? ?????? DataRow ?? ?????? ?????? DataTable. ?????? ????? ???? ????? ?? ?? ?? ??????. ????? ?????? ??? ????? ??? ????? ?? ??? ?????? ????????. ??? (0) ?? ???? ?????? ?????. iEnum
    IEnumerator* iEnum = tblAuthors->Rows->GetEnumerator();
            
     while(iEnum->MoveNext())
     {
            Console::WriteLine("{0}   {1}",dynamic_cast<String*>(dynamic_cast<DataRow *>(iEnum->Current)->get_Item("au_fname")),
                                           dynamic_cast<String*>(dynamic_cast<DataRow *>(iEnum->Current)->get_Item("au_lname")));
     }
    
  10. ??? ??????? ????? ??. ??????? ????? ? ???? ??? "????" ?????? ???????.



????? ??? ????????? ????????

// This is the main project file for the VC++ application project 
// that is generated by using the Application wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>
#using <System.Dll>
#using <System.Data.Dll>
#using <System.Xml.Dll>

using namespace System;
using namespace System::Data;
using namespace System::Xml;
using namespace System::Collections;
using namespace System::Data::SqlClient;

// This is the entry point for this application.
int _tmain(void)
{
    SqlConnection* objConn;
    try
    {

        
        String* sConnectionString;
        sConnectionString = "Password=myPassword;User ID=myUserID;Initial Catalog=pubs;Data Source=(local)";

        objConn = new SqlConnection(sConnectionString);
        objConn->Open();
        
        SqlDataAdapter* daAuthors = new SqlDataAdapter("Select * From Authors", objConn);
        DataSet* dsPubs = new DataSet("Pubs");
        
        daAuthors->FillSchema(dsPubs,SchemaType::Source, "Authors");
        daAuthors->Fill(dsPubs,"Authors");

        DataTable* tblAuthors = dsPubs->Tables->Item["Authors"];
        
        IEnumerator* iEnum = tblAuthors->Rows->GetEnumerator();
        
        while(iEnum->MoveNext())
        {
            Console::WriteLine("{0}   {1}",dynamic_cast<String*>(dynamic_cast<DataRow *>(iEnum->Current)->get_Item("au_fname")),
                                           dynamic_cast<String*>(dynamic_cast<DataRow *>(iEnum->Current)->get_Item("au_lname")));
            
        }
    }
    catch(Exception *ex)
    {
        Console::WriteLine( ex->Message );
    }
    __finally
    {
        objConn->Close();
    }
    
    return 0;
}
?????? ??? ????? ??????? ??? ??? ??????? ??? ?????? ??????? ??????? ?????? (/ clr:oldSyntax) ?? Visual C++ 2005 ????? ????? ????????? ???????? ?????? ?????. ?????? ??????? ??? ??? ??????? ??? ?????? ??????? ??????? ?????? ?? Visual C++ 2005 ???? ??????? ???????:
  1. ???? ??? Project ?? ???? ??? <ProjectName> ?????.

    ??????<ProjectName> ?????? ?????? ??? ???????.
  2. ?? ?????? ????? ????? ?? ???? ??? ???.
  3. ???? ?????? ??? ????? ????? ?????? ??? ? ?????? ??????? (/ clr:oldSyntax) ?? ??????? ??????? ????? "??? ????? ????? ??????" ?? ????? ?????? ???? ??? ????? ?? ???? ??? ?????.
?????? ??? ???? ?? ????????? ??? ??? ????? ????? ?????? ????? ?????? ?????? ??????? ??????? ?? ?????? ???? Microsoft ?????? ??? ?????:
/ ??? (??????? ??? ????? ????? ??????)
http://msdn2.microsoft.com/en-us/library/k8d11d4s.aspx

?????

????? ?? ?????????? ?? ?????? ????? Microsoft ??????? ??? ?????:

http://msdn2.microsoft.com/en-us/library/ms810293.aspx

http://msdn2.microsoft.com/en-us/library/ms973217.aspx

http://msdn.microsoft.com/net

???????

???? ???????: 818779 - ????? ??? ??????: 29/???? ??????/1428 - ??????: 3.2
????? ???
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft ADO.NET 1.1
  • Microsoft ADO.NET 1.0
????? ??????: 
kbmt kbsystemdata kbsqlclient kbhowtomaster kbhowto KB818779 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????818779

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com