DataTable コンストラクタ (String)
指定したテーブル名を使用して DataTable クラスの新しいインスタンスを初期化します。
名前空間: System.Data
アセンブリ: System.Data (system.data.dll 内)
構文
'宣言
Public Sub New ( _
tableName As String _
)
'使用
Dim tableName As String
Dim instance As New DataTable(tableName)
public DataTable (
string tableName
)
public:
DataTable (
String^ tableName
)
public DataTable (
String tableName
)
public function DataTable (
tableName : String
)
パラメータ
- tableName
テーブルに付ける名前。null 参照 (Visual Basic では Nothing) または空の文字列の場合は、DataTableCollection に追加したときに既定の名前が付けられます。
使用例
DataTable を作成し、それを DataGridView コントロールに表示する例を次に示します。
Private Sub MakeDataTableAndDisplay()
' Create new DataTable.
Dim table As DataTable = 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
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;
}
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 2.0、1.1、1.0
.NET Compact Framework
サポート対象 : 2.0、1.0
参照
関連項目
DataTable クラス
DataTable メンバ
System.Data 名前空間