Click here to Skip to main content
15,921,884 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Just wondered out of curiosity which one of these is the better way to Add a New row to a table in MyDataSet:

VB
Private Sub AddNewRow()
    Dim NewDataRowView as DataRowView = MyBindingSource.AddNew()
    Dim NewDataRow As MyDataset.MyTableRow = NewDataRowView.Row
    NewDataRow.BeginEdit()
    With NewDataRow
        .fkCreatedBy = intLoggedOnUserID
        .dtCreatedDate = DateTime.Now
    End With
    NewDataRow.EndEdit()
    MyBindingSource.EndEdit()
End Sub


OR

VB
Private Sub AddNewRow()
    Dim MyDataTable as MyDataset.MyTable
    Dim NewDataTableRow As MyTableRow = MyDataTable.NewDataTableRow
    With NewDataTableRow
        .fkCreatedBy = intLoggedOnUserID
        .dtCreatedDate = DateTime.Now
    End With
    MyDataTable.AddNewDataTableRow(NewDataTableRow)
End Sub


What I have tried:

I have tried both and i am not sure if there is any real difference but i am here to find out from more experienced people which is best practice.
Posted
Updated 30-Jan-18 13:05pm
v2

1 solution

You should add rows to a DataTable.

DataViews are normally used to get a subset (or all) records from a DataTable, if any of these are edited then the changes would be saved to the underlying data table & then the data source.
Typically DataViews are used for filtering and/or sorting data in a DataTable
While you can add new rows to a DataView you would need to consider why you have the extra level of extrapolation & complexity as they would update the underlying datatable anyway - refer; DataViews | Microsoft Docs[^]

Hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900