DataTable Oluşturucular

Tanım

DataTable sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

DataTable()

Bağımsız değişken olmadan sınıfının yeni bir örneğini DataTable başlatır.

DataTable(String)

Belirtilen tablo adıyla sınıfının yeni bir örneğini DataTable başlatır.

DataTable(SerializationInfo, StreamingContext)
Geçersiz.

DataTable sınıfının yeni bir örneğini serileştirilmiş verilerle başlatır.

DataTable(String, String)

Belirtilen tablo adını ve ad alanını kullanarak sınıfının yeni bir örneğini DataTable başlatır.

DataTable()

Kaynak:
DataTable.cs
Kaynak:
DataTable.cs
Kaynak:
DataTable.cs

Bağımsız değişken olmadan sınıfının yeni bir örneğini DataTable başlatır.

public:
 DataTable();
public DataTable ();
Public Sub New ()

Örnekler

Aşağıdaki örnek ve DataRowile DataColumn yeni DataTable bir oluşturur ve bunu bir DataGridView denetimde görüntüler.

private void MakeDataTableAndDisplay()
{
    // Create new DataTable.
    DataTable table = new DataTable();

    // Declare DataColumn and DataRow variables.
    DataColumn column;
    DataRow row;

    // Create new DataColumn, set DataType, ColumnName
    // and add to DataTable.
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.Int32");
    column.ColumnName = "id";
    table.Columns.Add(column);

    // Create second column.
    column = new DataColumn();
    column.DataType = Type.GetType("System.String");
    column.ColumnName = "item";
    table.Columns.Add(column);

    // Create new DataRow objects and add to DataTable.
    for(int i = 0; i < 10; i++)
    {
        row = table.NewRow();
        row["id"] = i;
        row["item"] = "item " + i;
        table.Rows.Add(row);
    }
    // Set to DataGrid.DataSource property to the table.
    dataGrid1.DataSource = table;
}
Private Sub MakeDataTableAndDisplay()
   ' Create new DataTable.
   Dim table As New DataTable

   ' Declare DataColumn and DataRow variables.
   Dim column As DataColumn
   Dim row As DataRow

   ' Create new DataColumn, set DataType, ColumnName 
   ' and add to DataTable.    
   column = New DataColumn
   column.DataType = System.Type.GetType("System.Int32")
   column.ColumnName = "id"
   table.Columns.Add(column)

   ' Create second column.
   column = New DataColumn
   column.DataType = Type.GetType("System.String")
   column.ColumnName = "item"
   table.Columns.Add(column)

   ' Create new DataRow objects and add to DataTable.    
   Dim i As Integer
   For i = 0 To 10
      row = table.NewRow
      row("id") = i
      row("item") = "item " & i
      table.Rows.Add(row)
   Next i

   ' Set to DataGrid.DataSource property to the table.
   DataGrid1.DataSource = table
End Sub

Açıklamalar

Oluşturucu, nesnenin DataTable tüm özellikleri için başlangıç değerlerini ayarlar. Aşağıdaki tabloda özellikler ve bunların varsayılan değerleri gösterilmektedir. Örneği DataTable oluşturulduğunda, aşağıdaki okuma/yazma özellikleri ilk değerlere ayarlanır.

Özellik Varsayılan değer
Casesensitive Bir öğeye aitse, üst öğesiyle DataSetaynı. Tersi durumda false.
Displayexpression Boş dize ("")
Yerel ayar Üst DataSet nesneninkiyle CultureInfo aynı (özelliği tarafından Locale döndürülür); üst öğe yoksa varsayılan, geçerli sistemdir CultureInfo.
MinimumKapacity 50 satır.

Bu özelliklerden herhangi birinin değerini, özelliğine ayrı bir çağrıyla değiştirebilirsiniz.

Ayrıca bkz.

Şunlara uygulanır

DataTable(String)

Kaynak:
DataTable.cs
Kaynak:
DataTable.cs
Kaynak:
DataTable.cs

Belirtilen tablo adıyla sınıfının yeni bir örneğini DataTable başlatır.

public:
 DataTable(System::String ^ tableName);
public DataTable (string? tableName);
public DataTable (string tableName);
new System.Data.DataTable : string -> System.Data.DataTable
Public Sub New (tableName As String)

Parametreler

tableName
String

Tabloya vermek için gereken ad. null ise veya boş bir dizeysetableName, öğesine DataTableCollectioneklendiğinde varsayılan bir ad verilir.

Örnekler

Aşağıdaki örnek bir DataTable oluşturur ve bunu bir DataGridView denetimde görüntüler.

private void MakeDataTableAndDisplay()
{
    // Create new DataTable.
    DataTable table = new DataTable("table");

    // Declare DataColumn and DataRow variables.
    DataColumn column;
    DataRow row;

    // Create new DataColumn, set DataType,
    // ColumnName and add to DataTable.
    column = new DataColumn();
    column.DataType = System.Type.GetType("System.Int32");
    column.ColumnName = "id";
    table.Columns.Add(column);

    // Create second column.
    column = new DataColumn();
    column.DataType = Type.GetType("System.String");
    column.ColumnName = "item";
    table.Columns.Add(column);

    // Create new DataRow objects and add to DataTable.
    for(int i = 0; i < 10; i++)
    {
        row = table.NewRow();
        row["id"] = i;
        row["item"] = "item " + i;
        table.Rows.Add(row);
    }
    // Set to DataGrid.DataSource property to the table.
    dataGrid1.DataSource = table;
}
Private Sub MakeDataTableAndDisplay()
   ' Create new DataTable.
   Dim table As New DataTable("table")

   ' Declare DataColumn and DataRow variables.
   Dim column As DataColumn
   Dim row As DataRow

   ' Create new DataColumn, set DataType, 
   ' ColumnName and add to DataTable.    
   column = New DataColumn
   column.DataType = System.Type.GetType("System.Int32")
   column.ColumnName = "id"
   table.Columns.Add(column)

   ' Create second column.
   column = New DataColumn
   column.DataType = Type.GetType("System.String")
   column.ColumnName = "item"
   table.Columns.Add(column)

   ' Create new DataRow objects and add to DataTable.    
   Dim i As Integer
   For i = 0 To 10
      row = table.NewRow
      row("id") = i
      row("item") = "item " & i
      table.Rows.Add(row)
   Next i

   ' Set to DataGrid.DataSource property to the table.
   DataGrid1.DataSource = table
End Sub

Ayrıca bkz.

Şunlara uygulanır

DataTable(SerializationInfo, StreamingContext)

Kaynak:
DataTable.cs
Kaynak:
DataTable.cs
Kaynak:
DataTable.cs

Dikkat

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

DataTable sınıfının yeni bir örneğini serileştirilmiş verilerle başlatır.

protected:
 DataTable(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected DataTable (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected DataTable (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Data.DataTable : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Data.DataTable
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Data.DataTable : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Data.DataTable
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parametreler

info
SerializationInfo

Veri kümesi için serileştirilmiş veriler.

context
StreamingContext

Seri hale getirilmiş akış hakkında bağlamsal bilgiler.

Öznitelikler

Özel durumlar

Yalnızca .NET 7 ve sonraki sürümleri: info ikili verileri içerir.

Açıklamalar

Oluşturucunun DataTable bu uygulaması için ISerializablegereklidir.

Ayrıca bkz.

Şunlara uygulanır

DataTable(String, String)

Kaynak:
DataTable.cs
Kaynak:
DataTable.cs
Kaynak:
DataTable.cs

Belirtilen tablo adını ve ad alanını kullanarak sınıfının yeni bir örneğini DataTable başlatır.

public:
 DataTable(System::String ^ tableName, System::String ^ tableNamespace);
public DataTable (string? tableName, string? tableNamespace);
public DataTable (string tableName, string tableNamespace);
new System.Data.DataTable : string * string -> System.Data.DataTable
Public Sub New (tableName As String, tableNamespace As String)

Parametreler

tableName
String

Tabloya vermek için gereken ad. null ise veya boş bir dizeysetableName, öğesine DataTableCollectioneklendiğinde varsayılan bir ad verilir.

tableNamespace
String

içinde DataTabledepolanan verilerin XML gösterimi için ad alanı.

Ayrıca bkz.

Şunlara uygulanır