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
Diggers - 14 Apr 2005 18:00 GMT
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 - 14 Apr 2005 20:44 GMT
sadly removing that line did not change anything.
> Hi Rod,
>
[quoted text clipped - 9 lines]
>
> Simon Rigby
Diggers - 14 Apr 2005 21:45 GMT
You say the app crashes. Any errors reported?
Simon
Bonnie Berent [C# MVP] - 18 Apr 2005 00:13 GMT
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
> I can't believe I am struggling with this, but I am.
>
[quoted text clipped - 26 lines]
>
> Rod