DataTable Konstruktor

Definisi

Menginisialisasi instans baru kelas DataTable.

Overload

DataTable()

Menginisialisasi instans DataTable baru kelas tanpa argumen.

DataTable(String)

Menginisialisasi instans DataTable baru kelas dengan nama tabel yang ditentukan.

DataTable(SerializationInfo, StreamingContext)
Kedaluwarsa.

Menginisialisasi instans DataTable baru kelas dengan data berseri.

DataTable(String, String)

Menginisialisasi instans DataTable baru kelas menggunakan nama tabel dan namespace yang ditentukan.

DataTable()

Sumber:
DataTable.cs
Sumber:
DataTable.cs
Sumber:
DataTable.cs

Menginisialisasi instans DataTable baru kelas tanpa argumen.

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

Contoh

Contoh berikut membuat baru DataTable dengan DataColumn dan DataRow, dan menampilkannya dalam DataGridView kontrol.

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

Keterangan

Konstruktor menetapkan nilai awal untuk semua properti DataTable objek. Tabel berikut ini memperlihatkan properti dan nilai defaultnya. Saat instans DataTable dibuat, properti baca/tulis berikut diatur ke nilai awal.

Properti Nilai default
CaseSensitive Sama seperti induk DataSet, jika itu milik satu. Sebaliknya, false.
DisplayExpression String kosong ("")
Lokal Sama seperti objek induk DataSet (dikembalikan oleh Locale properti); jika tidak ada induk, defaultnya adalah sistem CultureInfosaat CultureInfo ini .
MinimumCapacity 50 baris.

Anda dapat mengubah nilai untuk salah satu properti ini melalui panggilan terpisah ke properti .

Lihat juga

Berlaku untuk

DataTable(String)

Sumber:
DataTable.cs
Sumber:
DataTable.cs
Sumber:
DataTable.cs

Menginisialisasi instans DataTable baru kelas dengan nama tabel yang ditentukan.

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)

Parameter

tableName
String

Nama untuk memberikan tabel. Jika tableName adalah null atau string kosong, nama default diberikan saat ditambahkan ke DataTableCollection.

Contoh

Contoh berikut membuat DataTable dan menampilkannya dalam DataGridView kontrol.

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

Lihat juga

Berlaku untuk

DataTable(SerializationInfo, StreamingContext)

Sumber:
DataTable.cs
Sumber:
DataTable.cs
Sumber:
DataTable.cs

Perhatian

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

Menginisialisasi instans DataTable baru kelas dengan data berseri.

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)

Parameter

info
SerializationInfo

Data berseri untuk himpunan data.

context
StreamingContext

Informasi kontekstual tentang aliran berseri.

Atribut

Pengecualian

Hanya .NET 7 dan versi yang lebih baru: info berisi data biner.

Keterangan

Implementasi DataTable konstruktor ini diperlukan untuk ISerializable.

Lihat juga

Berlaku untuk

DataTable(String, String)

Sumber:
DataTable.cs
Sumber:
DataTable.cs
Sumber:
DataTable.cs

Menginisialisasi instans DataTable baru kelas menggunakan nama tabel dan namespace yang ditentukan.

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)

Parameter

tableName
String

Nama untuk memberikan tabel. Jika tableName adalah null atau string kosong, nama default diberikan saat ditambahkan ke DataTableCollection.

tableNamespace
String

Namespace layanan untuk representasi XML dari data yang disimpan di DataTable.

Lihat juga

Berlaku untuk