Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / April 2005

Tip: Looking for answers? Try searching our database.

Struggling to add a new Row to DataView

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rod - 14 Apr 2005 09:05 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.