JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

The DataRow Class

DataRow objects represent rows in a DataTable object. You use DataRow objects to get access to, insert, delete, and update the records in a table.

To create a new DataRow object, you usually use the NewRow method of a DataTable object, and after configuring the row with data, you can use the Add method to add the new DataRow to the table. In addition, you also can call the AcceptChanges method of the DataTable object to make that table treat the new row as it would its original data.

You can delete a DataRow from the Rows collection in a data table by calling the Remove method, or by calling the Delete method of the DataRow object itself. Note that the Remove removes the row from the collection, and the Delete method simply marks the DataRow for deletion. (The actual deletion occurs when you use the AcceptChanges method.)

So how do you actually get the data values stored in a particular field in a row? You can use the Item property, referring to the field by name or index. Here's how that looks in the ReadData example on the CD-ROM that we'll see in this chapter (see "Accessing Individual Data Items" in the Immediate Solutions):

For RowLoopIndex = 0 To (DataSet11.Tables("authors").Rows.Count - 1)
    For ColLoopIndex = 0 To (DataSet11.Tables("authors").Columns.Count - 1)
        TextBox1.Text &= _
    DataSet11.Tables("authors").Rows(RowLoopIndex).Item(ColLoopIndex) & _
    ControlChars.Tab & ControlChars.Tab
    Next ColLoopIndex
    TextBox1.Text &= ControlChars.CrLf
Next RowLoopIndex
Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor