Export (0) Print
Expand All
1 out of 4 rated this helpful - Rate this topic

DataRowCollection.Add Method

Adds a DataRow to the DataRowCollection.

Overload List

Adds the specified DataRow to the DataRowCollection object.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Sub Add(DataRow)
[C#] public void Add(DataRow);
[C++] public: void Add(DataRow*);
[JScript] public function Add(DataRow);

Creates a row using specified values and adds it to the DataRowCollection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Overridable Function Add(Object()) As DataRow
[C#] public virtual DataRow Add(object[]);
[C++] public: virtual DataRow* Add(Object*[]);
[JScript] public function Add(Object[]) : DataRow;

Example

[Visual Basic, C#, C++] The following example uses the Add method to create and add a new DataRow object to a DataRowCollection.

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of Add. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Private Sub AddRow(ByVal myTable As DataTable)
    Dim rc As DataRowCollection
    Dim myNewRow As DataRow
    ' Create an array with three elements.
    Dim rowVals(2) As Object
    rc = myTable.Rows
    rowVals(0) = "hello"
    rowVals(1) = "world"
    rowVals(2) = "two"
    ' Add and return the new row.
    myNewRow = rc.Add(rowVals) 
 End Sub

[C#] 
private void AddRow(DataTable myTable){
    DataRowCollection rc; 
    DataRow myNewRow;
    // Create an array with three elements.
    object[] rowVals = new object[3];
    rc = myTable.Rows;
    rowVals[0] = "hello";
    rowVals[1] = "world";
    rowVals[2] = "two";
    // Add and return the new row.
    myNewRow = rc.Add(rowVals);
 }

[C++] 
private:
void AddRow(DataTable* myTable){
    DataRowCollection* rc; 
    DataRow* myNewRow;
    // Create an array with three elements.
    Object* rowVals[] = new Object*[3];
    rc = myTable->Rows;
    rowVals[0] = S"hello";
    rowVals[1] = S"world";
    rowVals[2] = S"two";
    // Add and return the new row.
    myNewRow = rc->Add(rowVals);
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

DataRowCollection Class | DataRowCollection Members | System.Data Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.