DataTable.LoadDataRow method

xiaoxiao2021-03-06  19

.NET Framework class library

DataTable.LoadDataRow method

Find and update a specific row. If you can't find any match, create a new line using a given value.

[Visual Basic]

Public Function LoadDataRow (_

BYVAL VALUES () AS Object, _

BYVAL FACCEPTCHANGES AS BOOLEAN _

) AS DATAROW

[C #]

Public DataRow LoadDataRow

Object [] VALUES,

Bool facceptchange

);

[C ]

PUBLIC: DATAROW * LOADDATAROW

Object * Values ​​__gc [],

Bool facceptchange

);

[Jscript]

Public Function LoadDataRow

VALUES: Object [],

Facceptchanges: Boolean

: DATAROW;

parameter

Values

An array of values ​​used to create new rows.

Facceptchange

If you accept changes,

True; otherwise

False.

return value

New DataRow.

abnormal

The exception type condition The argumentException array is larger than the number of columns in the table. The invalidCastException value does not match its respective column types. The ConstraintException adds line will make the constraint invalid. NonulLallowedException Attempts to place null values ​​in columns in AllowDBnull.

Note

LoadDataRow method to extract the array and find matching value in the primary key column.

If a column has a default, a null value is transmitted in an array to set the default value for the column. Similarly, if the autotoincrement property set is true, a null value is transmitted in an array to set the automatically generated value for the row.

If the FacceptChanges parameter is true or not specified, add new data, then call AcceptChanges to accept all changes in the DataTable; if the parameter is false, the newly added row mark is inserted, and the existing row can be marked as modify.

An exception may also occur during ColumnChanging or RowChanging events. If an exception occurs, it is not added to the table.

Use LoadDataRow with BeginLoadData and EndloadData.

Example

[Visual Basic, C #, C ] The following example uses the LoadDataRow method to try to find the line. If this is not found, these values ​​will be used to create new rows.

[Visual Basic]

Private sub myaddupdate (byval myTable as dataatable)

'Create an Array for the VALUES.

DIM NewRow (2) As Object

'Set the values ​​of the array.

NEWROW (0) = "Hello"

NEWROW (1) = "world"

NEWROW (2) = "two"

Dim Myrow As DataRow

myTable.BeginLoadData ()

'Add the new row to the rows collection.

Myrow = MyTable.LoadDataRow (Newrow, True)

myTable.EndloadData ()

End Sub

[C #]

Private void myaddupdate (DATATABLE MyTable) {// Create An Array for the VALUES.

Object [] newrow = new object [3];

// set the values ​​of the array.

Newrow [0] = "Hello";

NEWROW [1] = "world";

NEWROW [2] = "two";

DataRow myrow;

MyTable.beginLoadData ();

// add the new row to the rows collection.

Myrow = myTable.loadDataRow (newrow, true);

Mytable.endloaddata ();

}

[C ]

Private:

Void myaddupdate (DATATABLE * MyTable) {

// Create an array for the value.

Object * newrow [] = new object * [3];

// set the values ​​of the array.

NEWROW [0] = s "Hello";

NEWROW [1] = s "world";

NEWROW [2] = s "TWO";

DataRow * Myrow;

MyTable-> BeginLoadData ();

// add the new row to the rows collection.

Myrow = myTable-> loadDatarow (newrow, true);

MyTable-> endloaddata ();

}

[JScript] There is no example available for JScript. To view Visual Basic, C # or C examples, click the "Language Filter" button in the upper left corner.

Claim

Platform: Windows 98, Windows NT 4.0, Windows ME, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 Series, .NET Framework Lite

See

DataTable class | DataTable member | system.data namespace

转载请注明原文地址:https://www.9cbs.com/read-42833.html

New Post(0)