Assembly : System.Data (dans system.data.dll)
SyntaxePublic Function NewRow As DataRow
Dim instance As DataTable Dim returnValue As DataRow returnValue = instance.NewRow
public DataRow NewRow ()
public:
DataRow^ NewRow ()
public DataRow NewRow ()
public function NewRow () : DataRow
Valeur de retour
DataRow possédant le même schéma que DataTable.
NotesVous devez utiliser la méthode NewRow pour créer de nouveaux objets DataRow possédant le même schéma que DataTable. Une fois DataRow créé, vous pouvez l'ajouter à DataRowCollection à l'aide de la propriété Rows de l'objet DataTable.
ExempleL'exemple suivant crée DataTable, ajoute deux objets DataColumn qui déterminent le schéma de la table et crée plusieurs nouveaux objets DataRow à l'aide de la méthode NewRow. Ces objets DataRow sont ensuite ajoutés à DataRowCollection à l'aide de la méthode Add.
Private Sub MakeDataTableAndDisplay() ' Create new DataTable and DataSource objects. Dim table As DataTable = New DataTable() ' Declare DataColumn and DataRow variables. Dim column As DataColumn Dim row As DataRow Dim view As DataView ' 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 9 row = table.NewRow() row("id") = i row("item") = "item " & i table.Rows.Add(row) Next ' Create a DataView using the DataTable. view = New DataView(table) ' Set a DataGrid control's DataSource to the DataView. DataGrid1.DataSource = view End Sub
private void MakeDataTableAndDisplay() { // Create new DataTable and DataSource objects. DataTable table = new DataTable(); // Declare DataColumn and DataRow variables. DataColumn column; DataRow row; DataView view; // 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.ToString(); table.Rows.Add(row); } // Create a DataView using the DataTable. view = new DataView(table); // Set a DataGrid control's DataSource to the DataView. dataGrid1.DataSource = view; }
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ