System.Data Namespace DataRow Class
Sets or retrieves the data stored in the column specified by name.
Object variable = DataRow.Item [ columnName ];
... or ...
Object variable = DataRow [ columnName ];
dim variable as Object = DataRow.Item ( columnName )
... or ...
dim variable as Object = DataRow ( columnName )
variable : Object = DataRow.Item ( columnName );
... or ...
variable : Object = DataRow ( columnName ); |
|
C# |
VB |
JScript |
- columnName
- The name of the column.
An Object that contains the data.
When setting the property, an exception will be thrown if an exception occurs in the ColumnChanging event. If this is an immediate edit, see EndEdit for the exceptions that can be thrown.
The following examples demonstrate using the second syntax of the Item property to get or set the value of a given column name in a specified row.
In the first example, tblSource.Rows [ rowIndex-1 ]
returns the reference to the DataRow, and PlanId is the column name. The returned value is then used to set the RowFilter of the default DataView associated with the parent DataTable of the row.
DataView getView ( int rowIndex ) {
DataTable tblSource = ( DataTable ) Session [ "tblSource" ];
tblSource.DefaultView.RowFilter = "PlanID='" + tblSource.Rows [ rowIndex-1 ] [ "PlanId" ] + "'";
return tblSource.DefaultView;
}
Function getView ( rowIndex As Integer ) As DataView
Dim tblSource As DataTable = CType ( Session ( "tblSource" ), DataTable )
tblSource.DefaultView.RowFilter = "PlanID='" + tblSource.Rows ( rowIndex - 1 ) ( "PlanId" ) + "'"
Return tblSource.DefaultView
End Function |
|
C# |
VB |
In the second example, myTable.Rows [ .Item.ItemIndex ]
returns the reference to the DataRow, and the row values are then set from user input.
// get and update row
DataRow myRow = myTable.Rows [ .Item.ItemIndex ];
myRow [ "ContactName" ] = contact;
myRow [ "ContactTitle" ] = title;
myRow [ "Address" ] = address;
myRow [ "City" ] = city;
myRow [ "Phone" ] = phone;
myTable.AcceptChanges ( );
' get and update row
Dim myRow As DataRow = myTable.Rows ( e.Item.ItemIndex )
myRow ( "ContactName" ) = contact
myRow ( "ContactTitle" ) = title
myRow ( "Address" ) = address
myRow ( "City" ) = city
myRow ( "Phone" ) = phone
myTable.AcceptChanges ( ) |
|
C# |
VB |
DataRow Members DataRow.Item Overload List