DataReader GetSchemaTable ?????? ?? Visual C# ?? ????? ???? ????? ?????? ??????? ???? ?? ??? ????????

???? ?????? ???? ??????
???? ID: 310107 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

?? ???? ??? ADO DataReader ???????? ?? GetSchemaTable ???? ?? ????? ???? ?? ??? ???? ????????? ???? ?? ???????? ?????? ??????? ??????? ???? ?? ??? NET. ???? ???? ????? ?? ?????? ?? ??? ??? ?????? ??? ??? ????? ?????? ??????? ????? ?? ???? ??? ?????????? ??????? ????? ??:
  • ???
  • ???? ??????
  • ????
  • ??? ????? ?? ???? ?? ???????? ????? ?????? ????? ??
  • ??? ????? ?? ???? ????? autonumber (AutoIncrement) ?? ??????
GetSchemaTable ???? ?? ??? ?? DataReader????? ?????? ??? ?? DataTable ??? ???? ??? DataTable ??? resultset ???????? ??????? ?? ??? ?? ?????? ??? ???????? ????? ??? ??? ?????? ??? resultset ???? ?? ???? DataTable ????? ?? ColumnName ??? ?????? ?? ???, ???? ColumnName, ???? ??????, ColumnSize, IsKeyColumn, ?? IsAutoIncrement ??? ?? ??? ??? DataTable ????? ?? ??? ?????? ?? ???, ???? ????? ??? ??? ColumnName ??? ?? ??? ??? ???
??? ?? ?? ?????? ?? ?????? ???????? ????? ???????, ??????? ???? ?? ??? ???????? ????? ??? ?? ??? ????? ?? ???? ?? AutoIncrement ?????? ??, ?? CommandBehavior.KeyInfo?? ??? DataReader ?? CommandBehavior ??? ??? ???? ??????

?? ?? ?? OLE DB ?? ??? GetSchemaTable ???? ?? ????? ?? ???? ??????? ??????? ?? SQL.??? ???????? OleDbDataReader.GetSchemaTable ???? OLE DB IColumnsRowset::GetColumnsRowset ?????? ?? ??? ???? ??? ???? OLE DB ??????? ??? SqlDataReader.GetSchemaTable ?????? ?? ????? ???? ?????

??????? ??, ?? ?????? ??? ?? GetSchemaTable ???? ?? ????? ???? ?? ?? ?? ????? ?????? DataReader ???? ???? ???? ??? ??? ??, ????? ?????? ??????? ???? ?? ??? GetSchemaTable ?? ????? ???? ???, ?? ?? DataReader?????? ???? ?? ????? DataReader ????? ' ???? ????? ?? ???, ???? ??? ?????? ?? ???? ??? ?? ????????

?? GetSchemaTable ???? ?? ????? ???? ?? ???

  • SqlConnection ???????? SQL Server ?????? ??????? ??????? ?? ??? ?? ?? ?????? ???? ???? OleDbConnection ???????? ?? GetOleDbSchemaTable ???? ???? ?? ??? analogous ?????? ???? GetSchemaTable ???? SqlDataReader ???? ?? ????? ?????? ??????? ???? ?? straightforward ????? ?????? ???? ?? SQL ????? ?? ????????
  • ?????? OleDbConnection ???????? ?? GetOleDbSchemaTable ???? ???????, ?????? ?? ????? ?????? ??????? ???? ?? ???? ???, DataReader ???????? ?? GetSchemaTable ???? ???? ????? ??????? ???? ????? ??? ?? ????? ???? ?? ??? ???? ?? ?? ??? ???? ?? ?????? ????????
  • ?? ????? ??? ?? ????? ?? ???????? ???? ??? ???? ?????? DataTable ??? ?? ?????? ?? ?????? ??? ?? DataTable ????? ?? ??? GetSchemaTable ?????? ?? ????? ?? ???? ??? ????? ?????????? "????? ???????? ?????: Fitch ???? ?? ??? ?? ?? ?? ???? ????????? ???? ?? ??? GetSchemaTable ?? ????? ???? ?? ??? ???? ????????? ???? ?? ?? ????? ??? ?? ???, ????? ?? Mather 7.0 ????? SQL ??????"Microsoft ????? ???????? ??? ???????? ?????? ??????????? ??? ????

OLE DB ?? ??? ????? ?????? ??????? ?????? ???????

?? ????? (?????? ????? ?? ?????? ??????? ???????? ???? ?? ???) ?? ??????????? ?????? SQL ????? ????????? ??? ????????

OLE DB ?? ????? ???? ??? ?? ??? ????? ??? ??????? ?? ????? GetSchemaTable ???? OleDbDataReader ???????? ???
  1. ????? ???????? ?? ??????? ?????NET, ?? ??? ????? ?? ?? Visual C# ????? ????????? ?????????? ???????? ??? ?? Class1.cs ?? ???? ???
  2. Class1 ?? ??? ??? ????? ?????? ????? ??? ??????? ???????? ????? ??? ??? ??? ????? ?? ????? ??:
    using System.Data;
    using System.Data.OleDb;
    					
  3. ??? ????? ???, ????? ??????? ??? ????? ??? ???????:
    OleDbConnection cn = new OleDbConnection();
    OleDbCommand cmd = new OleDbCommand();
    DataTable schemaTable; 
    OleDbDataReader myReader; 
    			 
    //Open a connection to the SQL Server Northwind database.
    cn.ConnectionString = "Provider=SQLOLEDB;Data Source=server;User ID=login;
                           Password=password;Initial Catalog=Northwind";
    cn.Open();
    
    //Retrieve records from the Employees table into a DataReader.
    cmd.Connection = cn;
    cmd.CommandText = "SELECT * FROM Employees";
    myReader = cmd.ExecuteReader(CommandBehavior.KeyInfo); 
    
    //Retrieve column schema into a DataTable.
    schemaTable = myReader.GetSchemaTable();
    
    //For each field in the table...
    foreach (DataRow myField in schemaTable.Rows){
        //For each property of the field...
        foreach (DataColumn myProperty in schemaTable.Columns) {
    	//Display the field name and value.
    	Console.WriteLine(myProperty.ColumnName + " = " + myField[myProperty].ToString());
        }
        Console.WriteLine();
    
        //Pause.
        Console.ReadLine();
    }
    
    //Always close the DataReader and connection.
    myReader.Close();
    cn.Close();
    					
  4. ???????? ??? ?????? ?? SQL ????? ?? ?????? ???? ?? ??? ConnectionString ??? ?? ??????? ???? ?????????
  5. ?????? ???? ?? ????????? ?? ????? ?? ??? F5 ????? ?????? ????? ???????? ?????? ?? ????? ?? ????? ????? ??? ???????? ?? ?? ????
  6. ???? ?? ?????? ?? ??????? ???? ?? ???, ?? ????? ?? ?????? ???? ?? ??? ENTER ????? ?????????, ?? ?????? ????? ?????? ?? ????? (IDE)?

????? ?????? SQL ?? ??????? ?????? ???????

?? ????? (?????? ????? ?? ?????? ??????? ???????? ???? ?? ???) ?? ??????????? ?????? SQL ????? ????????? ??? ????????

??? ?? SQL ?? ????? ???? ??? ?? ??? ?????? ???????, ?? GetSchemaTable ???? SqlDataReader ???????? ?? ????? ?????
  1. ????? ???????? ?? ??????? ?????NET, ?? ?? ??? Visual C# ????? ????? ????????? ?????????? ???????? ??? ?? Class1.cs ?? ???? ???
  2. Class1 ?? ??? ??? ????? ?????? ????? ??? ??????? ???????? ????? ??? ??? ??? ????? ?? ????? ??:
    using System.Data;
    using System.Data.SqlClient;
    					
  3. ??? ????? ???, ????? ??????? ??? ????? ??? ???????:
    SqlConnection cn = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    DataTable schemaTable; 
    SqlDataReader myReader; 
    			 
    //Open a connection to the SQL Server Northwind database.
    cn.ConnectionString = "Data Source=server;User ID=login;
                           Password=password;Initial Catalog=Northwind";
    cn.Open();
    
    //Retrieve records from the Employees table into a DataReader.
    cmd.Connection = cn;
    cmd.CommandText = "SELECT * FROM Employees";
    myReader = cmd.ExecuteReader(CommandBehavior.KeyInfo);
    
    //Retrieve column schema into a DataTable.
    schemaTable = myReader.GetSchemaTable();
    
    //For each field in the table...
    foreach (DataRow myField in schemaTable.Rows){
        //For each property of the field...
        foreach (DataColumn myProperty in schemaTable.Columns) {
    	//Display the field name and value.
    	Console.WriteLine(myProperty.ColumnName + " = " + myField[myProperty].ToString());
        }
        Console.WriteLine();
    
        //Pause.
        Console.ReadLine();
    }
    
    //Always close the DataReader and connection.
    myReader.Close();
    cn.Close();
    					
  4. ???????? ??? ?????? ?? SQL ????? ?? ?????? ???? ?? ??? ConnectionString ??? ?? ??????? ???? ?????????
  5. ?????? ???? ?? ????????? ?? ????? ?? ??? F5 ?????? ????? ??? ?? ???????? ?????? ?? ????? ?? ????? ????? ??? ???????? ???? ????
  6. ???? ?? ?????? ?? ??????? ???? ?? ???, ?? ????? ?? ?????? ???? ?? ??? ENTER ????? ?????????, ?? IDE ?? ??????

??????

DataReader ?? GetSchemaTable ?? ??? ???? ?? ???? ??? ???? ??????? ?? ???, ????? ???????? ??? ????? ???? ????????? ?????? ??????????? ??? ???:
DataReader ?? ????? ?? ???? ???????????? ?? ??? ??

IDataReader.GetSchemaTable ????

???: ?? ???? ??? ??????? ?? ???? ???? ????? ???? ?? DataTable??? ???

OleDbDataReader.GetSchemaTable ????

SqlDataReader.GetSchemaTable ????
?????? ??????? ??????? ???? ?? ??? OleDbConnection ???????? ?? GetOleDbSchemaTable ???? ?? ????? ?? ?? ???? ??? ???????? ??????? ?? ???, ???? ?????? ?? ????? ???? ????? Microsoft ???????? ??? ???? ????? ?? ???:
309681 GetOleDbSchemaTable ?? Visual C# ?? ????? ???? ?????? ??????? ??????? ???? ?? ??? ????????

???

???? ID: 310107 - ????? ???????: 12 ??? 2012 - ??????: 3.0
???? ???? ???? ??:
  • Microsoft ADO.NET 1.1
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
??????: 
kbdatabase kbhowtomaster kbsqlclient kbsystemdata kbmt KB310107 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:310107

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

 

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