System.Data.DataRow
A DataRow represents an individual row (or record) in a DataTable.
Each DataRow contains one or more fields which can be accessed through the Item property.
if (objDataRow Is System.DBNull.Value)
{
}
Creating a DataRow Object
Dim objDataRow As System.Data.DataRow
objDataRow = objDataTable.NewRow()
or
Dim objDataRow As New System.Data.DataRow
Adding a DataRow
objDataTable.Rows.Add(objDataRow)
Inserting a DataRow
It is also possible to insert rows into any position in a DataTable.
objDataTable.Rows.InsertAt(objDataRow)
Editing a DataRow
objDataRow.BeginEdit
objDataRow("Column1") = "NewValue"
objDataRow.EndEdit
Adding DataRows
objDataTable.BeginLoadData()
For iRowNo = 1 To 100
objDataRow.Item("Column1") = "Value1"
objDataRow.Item("Column2") = "Value2"
objDataTable.LoadDataRow(objDataRow)
Next iRowNo
objDataTable.EndLoadData()
Dim objDataRow As System.Data.DataRow
objDataRow = clsDataSet.mobjDataSet.Tables(sTableName).NewRow
objDataRow.Item(0) = "some text"
objDataRow.Item(1) = "some more text"
objDataRow.Item(2) = "even more text"
objDataSet.Tables(sTableName).Rows.Add(objDataRow)
Updating DataRows
Dim objDataRow As New System.Data.DataRow
For iRowNo = 1 To 100
objDataRow = objDataTable.Rows(iRowNo)
objDataRow.Item("Column1") = "Value1"
Next iRowNo
Alternatively you can refer to the DataRow objects directly.
For iRowNo = 1 To 100
objDataTable.Rows(iRowNo)("Column1") = "Value1"
Next iRowNo
Deleting a DataRow
Using the Delete method does not actually delere the row from the DataTable but just changes its RowState to Deleted.
objDataTable.Rows(2).Delete
If you want to permanently remove a DataRow without the chance of getting it back later you can use the Remove method of the Rows collection
objDataTable.Rows.Remove(2)
RowState Properties
Detached | The row has been created but has not been added to a DataTable. |
Added | The row has been added to a DataTable. |
Modified | The row has been updated. |
Deleted | The row has been deleted. |
Unchanged | The row has not been modified. |
Properties
HasErrors | Returns True is there are errors in the column collection. |
Item | Gets or sets the data stored in the xpecified column. The argument can be the column name, the column index, or a DataColumn object. An optional DataRowVersion argument lets you retrieve the current, original, proposed or default value for the column. |
ItemArray | Gets or sets the values of all the columns using an Object array. |
RowError | Gets or sets a string containing the custom error description for the current row. |
RowState | The current state of this row; can be Unchanged, Modified, Added, Deleted or Detached. |
Table |
Methods
AcceptChanges | Commits all changes to this DataRow after it was loaded or since the most recent AcceptChanges method |
BeginEdit | Marks the beginning of an edit operation on the DataRow. |
CancelEdit | Cancels all the changes to the DataRow since the most recent BeginEdit. |
ClearErrors | Clear all the errors for this row, including the RowError property and errors set with the SetColumnError method. |
Delete | Deletes this row. Changes the RowState to Deleted. |
EndEdit | Confirms all the changes to the DataRow since the most recent BeginEdit method. |
GetChildRows | Returns an array of the DataRow objects that are the child rows of the current row, following the relationship specified by the argument, which can be a relationship name or a DataRelation object. An optional second argument lets you refer to a specific DataRowVersion for the rows to be retrieved. |
GetColumnError | Returns the error description for the error in the column specified by the argument which can be the column name, column index or a DataColumn object. |
GetColumnsInError | Returns the array of DataColumn objects that have an error. |
GetParentRow | Returns the parent DataRow object following the relationship specified by the argument (which can be one of the values accepted by the GetChildRows method). |
GetParentRows | Returns an array of the parent DataRow objects following the relationship specified by the argument (which can be one of the values accepted by the GetChildRows method). |
GetType | |
IsNull | Returns Truw if the specified column has a null value. The argument can be a colum name, column index or a DataColumn object. An optional second argument lets you refer to a specific DataRowVersion value. |
RejectChanges | Rejects all changes to this DataRow after it was loaded or since the most recent AcceptChanges method. |
SetColumnError | Sets an error description for the specified column. |
SetParentRow | Sets the parent DataRow for the current row. |
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext