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

DetachedThe row has been created but has not been added to a DataTable.
AddedThe row has been added to a DataTable.
ModifiedThe row has been updated.
DeletedThe row has been deleted.
UnchangedThe row has not been modified.

Properties

HasErrorsReturns True is there are errors in the column collection.
ItemGets 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.
ItemArrayGets or sets the values of all the columns using an Object array.
RowErrorGets or sets a string containing the custom error description for the current row.
RowStateThe current state of this row; can be Unchanged, Modified, Added, Deleted or Detached.
Table 

Methods

AcceptChangesCommits all changes to this DataRow after it was loaded or since the most recent AcceptChanges method
BeginEditMarks the beginning of an edit operation on the DataRow.
CancelEditCancels all the changes to the DataRow since the most recent BeginEdit.
ClearErrorsClear all the errors for this row, including the RowError property and errors set with the SetColumnError method.
DeleteDeletes this row. Changes the RowState to Deleted.
EndEditConfirms all the changes to the DataRow since the most recent BeginEdit method.
GetChildRowsReturns 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.
GetColumnErrorReturns 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.
GetColumnsInErrorReturns the array of DataColumn objects that have an error.
GetParentRowReturns the parent DataRow object following the relationship specified by the argument (which can be one of the values accepted by the GetChildRows method).
GetParentRowsReturns 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 
IsNullReturns 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.
RejectChangesRejects all changes to this DataRow after it was loaded or since the most recent AcceptChanges method.
SetColumnErrorSets an error description for the specified column.
SetParentRowSets the parent DataRow for the current row.

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext