Struggling to add a new Row to DataView

  • Thread starter Thread starter Rod
  • Start date Start date
R

Rod

I can't believe I am struggling with this, but I am.

I have a form with the controls bound to a DataView.
The form has an "add" button which is meant to add a new row.

I do this with the code below
_______________________
Dim newDataRowView As DataRowView = MembersDataView.AddNew

newDataRowView("Date Joined") = DateTime.Today

newDataRowView.EndEdit()

newDataRowView = Nothing

_______________________

I was hoping to see a blank form appear, but no.

If I go through all the records there is no evidence of the new row.

The Currency Manager does not admit to there being an extra row. (ie count
is unchanged)

Something has changed because when I use the Data Adapter to update the
source database the program crashes.

Any help very much appreciated.

Rod
 
Hi Rod,

I would say the line newDataRowView = nothing is the problem.

Your variable (newDataRowView) is a reference returned reference from
AddView method of the DataView. You are setting the added row to
nothing in your last line, and hence the row you have added is now
nothing. If your app crashes with NullReferenceException or similar, I
would say that this is definitely the case.

Hope this helps

Simon Rigby
 
Rod,

The DataRowView works similarly to the DataRow ... you've created a new row,
but you haven't actually added it to your DataView (or it's DataTable) yet.

After you create the new DataRowView, you need to explicitly add it to your
DataView. So, after your .EndEdit(), do this:

MembersDataView.Table.Rows.Add(newDataRowView.Row);

~~Bonnie
 
Back
Top