Sideway
output.to from Sideway
Draft for Information Only

Content

System.Data Namespace Component
DataRowCollection Class
 Definition
  In this article
 Examples
 Remarks
 Properties
 Methods
 Extension Methods
 Applies to
   .NET Core
   .NET Framework
   .NET Standard
   Xamarin.Android
   Xamarin.iOS
   Xamarin.Mac
 Thread Safety
 See also
 Examples
 Source/Reference

System.Data Namespace Component

The System.Data namespace provides access to classes that represent the ADO.NET architecture. ADO.NET lets you build components that efficiently manage data from multiple data sources.

DataRowCollection Class

Definition

Namespace:
System.Data
Assemblies:
System.Data.dll, netstandard.dll, System.Data.Common.dll

Represents a collection of rows for a DataTable.

In this article

  1. Definition
  2. Examples
  3. Remarks
  4. Properties
  5. Methods
  6. Extension Methods
  7. Applies to
  8. Thread Safety
  9. See also
C#
[System.Serializable]
public sealed class DataRowCollection : System.Data.InternalDataCollectionBase
Inheritance
Object InternalDataCollectionBase DataRowCollection
Attributes
SerializableAttribute

Examples

The first example in this section prints the value of column 1 for every row in a DataRowCollection. The second example adds a new row created by using the NewRow method to the DataRowCollection.

C#
private void ShowRows(DataTable table)
{
    // Print the number of rows in the collection.
    Console.WriteLine(table.Rows.Count);
    // Print the value of columns 1 in each row
    foreach(DataRow row in table.Rows)
    {
        Console.WriteLine(row[1]);
    }
}

private void AddRow(DataTable table)
{
    DataRowCollection rowCollection = table.Rows;
    // Instantiate a new row using the NewRow method.

    DataRow newRow = table.NewRow();
    // Insert code to fill the row with values.

    // Add the row to the DataRowCollection.
    table.Rows.Add(newRow);
}

Remarks

The DataRowCollection is a major component of the DataTable. While the DataColumnCollection defines the schema of the table, the DataRowCollection contains the actual data for the table, where each DataRow in the DataRowCollection represents a single row.

You can call the Add and Remove methods to insert and delete DataRow objects from the DataRowCollection. You can also call the Find method to search for DataRow objects that contain specific values in primary key columns, and the Contains method to search character-based data for single words or phrases.

For other operations, such as sorting or filtering the DataRowCollection, use methods on the DataRowCollection's associated DataTable.

Properties

Count

Gets the total number of DataRow objects in this collection.

IsReadOnly

Gets a value that indicates whether the InternalDataCollectionBase is read-only.

(Inherited from InternalDataCollectionBase)
IsSynchronized

Gets a value that indicates whether the InternalDataCollectionBase is synchronized.

(Inherited from InternalDataCollectionBase)
Item[Int32]

Gets the row at the specified index.

List

Gets the items of the collection as a list.

(Inherited from InternalDataCollectionBase)
SyncRoot

Gets an object that can be used to synchronize the collection.

(Inherited from InternalDataCollectionBase)

Methods

Add(DataRow)

Adds the specified DataRow to the DataRowCollection object.

Add(Object[])

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

Clear()

Clears the collection of all rows.

Contains(Object)

Gets a value that indicates whether the primary key of any row in the collection contains the specified value.

Contains(Object[])

Gets a value that indicates whether the primary key columns of any row in the collection contain the values specified in the object array.

CopyTo(Array, Int32)

Copies all the DataRow objects from the collection into the given array, starting at the given destination array index.

CopyTo(DataRow[], Int32)

Copies all the DataRow objects from the collection into the given array, starting at the given destination array index.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Find(Object)

Gets the row specified by the primary key value.

Find(Object[])

Gets the row that contains the specified primary key values.

GetEnumerator()

Gets an IEnumerator for this collection.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
IndexOf(DataRow)

Gets the index of the specified DataRow object.

InsertAt(DataRow, Int32)

Inserts a new row into the collection at the specified location.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(DataRow)

Removes the specified DataRow from the collection.

RemoveAt(Int32)

Removes the row at the specified index from the collection.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

.NET Core

3.0 Preview 8 2.2 2.1 2.0

.NET Framework

4.8 4.7.2 4.7.1 4.7 4.6.2 4.6.1 4.6 4.5.2 4.5.1 4.5 4.0 3.5 3.0 2.0 1.1

.NET Standard

2.1 Preview 2.0

Xamarin.Android

7.1

Xamarin.iOS

10.8

Xamarin.Mac

3.0

Thread Safety

This type is safe for multithreaded read operations. You must synchronize any write operations.

See also

 

Examples

Examples of DataRowCollection Class
ASP.NET Code Input:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
       <title>Sample Page</title>
       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
       <script runat="server" >
           Sub Page_Load()
               Dim xstr As String
               Dim xconn As New System.Data.OleDb.OleDbConnection
               xconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=T:\test.mdb;User Id=admin;Password=;"
               xconn.Open()
               xstr = xstr + "Connection xconn to database test.mdb  is opened successfully.<br />"
               Dim xdata As New System.Data.DataSet
               Dim xadapt As System.Data.OleDb.OleDbDataAdapter
               Dim sql As String = "SELECT * FROM T1"
               xadapt = New System.Data.OleDb.OleDbDataAdapter(sql, xconn)
               xstr = xstr + "Dataadapter xadapt is assigned to SELECT * FROM T1 through xconn successfully.<br />"
               xadapt.Fill(xdata,"T1")
               xstr = xstr + "Dataset xdata is filled by xadapt.fill successfully.<br />"
               xstr = xstr + "<br />"
               Dim xrows As System.Data.DataRowCollection
               xstr = xstr + "Declare a table row collection, xrows<br />"
               xrows = xdata.tables(0).Rows
               xstr = xstr + "Assign xdata.tables(0).Columns to table rowcollection, xrows <br />"
             xstr = xstr  + "->xrows.Count: " + xrows.Count.ToString + "<br />"
               xstr = xstr  + "->xrows.Item(0): " + xrows.Item(0).ToString + "<br />"
               xdata.tables(0).PrimaryKey = New System.Data.DataColumn(){xdata.tables(0).Columns("id")}
               xstr = xstr + "Assign xdata.tables(0).Columns(id) as primary key of table xdata.tables(0)<br />"
               xstr = xstr  + "->xrows.find(1): " + xrows.Find("1").ToString + "<br />"
               xstr = xstr  + "->xrows.contains(1): " + xrows.Contains("1").ToString + "<br />"
               xstr = xstr  + "->xrows.indexof(xrows.Find(1)): " + xrows.IndexOf(xrows.Find("1")).ToString + "<br />"
               Dim xrowvau As Object() = New Object(){"111","s","d"}
               xstr = xstr  + "Declare a new rowvalue, xrowvau <br />"
               xrows.Add(xrowvau)
               xstr = xstr  + "Row xrowvau is added to rowcollection xrows through xrows.Add(xrowvau)<br />"
               Dim xrow As System.Data.DataRow = xdata.Tables(0).NewRow()
               xstr = xstr  + "Declare a new row, xrow by xdata.Tables(0).NewRow()<br />"
               xrow(0) = "112"
               xrow(1) = "fg2"
               xrow(2) = "dt"
               xstr = xstr  + "Assign values to row, xrow<br />"
               xrows.InsertAt(xrow,2)
               xstr = xstr  + "Row xrow is added to rowcollection xrows through xrows.InsertAt(xrow,2)<br />"
               xrows.RemoveAt(3)
               xstr = xstr  + "xrows(3) is removed from rowcollection xrows through xrows.RemoveAt(3)<br />"
               xrows.Remove(xrow)
               xstr = xstr  + "Row xrow is removed from rowcollection xrows through xrows.Remove(xrow)<br />"
               xrows.Clear()
               xstr = xstr  + "Rowcollection xrows is cleared<br />"
               xstr = xstr + "<br />"
               xadapt.Dispose()
               xstr = xstr + "Dataadapter xadapt is disposed successfully.<br />"
               xconn.Close()
               xstr = xstr + "Connection xconn is closed successfully.<br />"
               xdata.Dispose()
               xstr = xstr + "Dataset xdata is disposed successfully.<br />"
               
               lbl01.Text = xstr
           End Sub
       </script>
    </head>
    <body>
       <% Response.Write ("<h1>This is a Sample Page of DataRowCollection Class</h1>") %>
       <p>
           <%-- Set on Page_Load --%>
           <asp:Label id="lbl01" runat="server" />
       </p>
    </body>
</html>
HTML Web Page Embedded Output:

Source/Reference


©sideway

ID: 201100010 Last Updated: 11/10/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019