DataSet.GetXmlSchema Metodo

Definizione

Restituisce lo schema XML per la rappresentazione XML dei dati memorizzati nell'oggetto DataSet.

public:
 System::String ^ GetXmlSchema();
public string GetXmlSchema ();
member this.GetXmlSchema : unit -> string
Public Function GetXmlSchema () As String

Restituisce

String

Stringa che rappresenta lo schema XML per la rappresentazione XML dei dati memorizzati nell'oggetto DataSet.

Esempio

Nell'esempio seguente viene creato un DataSet oggetto e DataTablee quindi viene visualizzato lo schema in formato XML.

private static void DemonstrateGetXml()
{
    // Create a DataSet with one table containing
    // two columns and 10 rows.
    DataSet dataSet = new DataSet("dataSet");
    DataTable table = dataSet.Tables.Add("Items");
    table.Columns.Add("id", typeof(int));
    table.Columns.Add("Item", typeof(string));

    // Add ten rows.
    DataRow row;
    for(int i = 0; i <10;i++)
    {
        row = table.NewRow();
        row["id"]= i;
        row["Item"]= "Item" + i;
        table.Rows.Add(row);
    }

    // Display the DataSet contents as XML.
    Console.WriteLine( dataSet.GetXml() );
}
Private Shared Sub DemonstrateGetXml()
    ' Create a DataSet with one table 
    ' containing two columns and 10 rows.
    Dim dataSet As New DataSet("dataSet")
    Dim table As DataTable = dataSet.Tables.Add("Items")
    table.Columns.Add("id", Type.GetType("System.Int32"))
    table.Columns.Add("Item", Type.GetType("System.String"))

    ' Add ten rows.
    Dim row As DataRow
    Dim i As Integer
    For i = 0 To 9
        row = table.NewRow()
        row("id") = i
        row("Item")= "Item" & i
        table.Rows.Add(row)
    Next

    ' Display the DataSet contents as XML.
    Console.WriteLine( dataSet.GetXml() )
End Sub

Commenti

La chiamata a questo metodo è identica alla chiamata WriteXmlSchema, ad eccezione del fatto che viene scritto solo lo schema primario.

GetXmlSchema restituisce XML come stringa e pertanto richiede un sovraccarico maggiore di quello di WriteXmlSchema scrivere XML in un file.

Se si compila un oggetto usando l'inferenza DataSet dello schema e serializzarlo usando i servizi XML o Web, l'ordinamento delle colonne può cambiare.

Si applica a

Vedi anche