Re: Adding Rows to Data-Bound DataGridView
- From: "Miro" <miro@xxxxxxxxx>
- Date: Thu, 13 Mar 2008 15:06:38 -0400
I might have to scratch that. ( just checked the website )
For beign a begininner as much as I am...I cannot justify a cost of 500 yet for 1 day.
But Great book!
Miro
"Miro" <miro@xxxxxxxxx> wrote in message news:ueW6mzThIHA.6084@xxxxxxxxxxxxxxxxxxxxxxx
Hey,
You updated your 2008 tour schedule.
Ive been peaking on your webstie for months to see where you will be in 2008.
Might see you there.
Cheers'
Miro
"William Vaughn" <billvaNoSPAM@xxxxxxxxx> wrote in message news:F8CF795B-0116-47C8-A504-457E3AF706C1@xxxxxxxxxxxxxxxxChapter 7 discusses these issues. Start on page 468.
No, when you have created a DataSet (strongly typed or untyped) and bound it to a complex bound control like a DataGridView, once you change the Rows collection members (add or delete rows, or change values in existing rows) the binding mechanism posts these changes to the bound control. You might have to execute EndEdit to get this operation to fire but it's posted automatically. You should not have to call "AcceptChanges" in 90% of the cases when handling data. AcceptChanges is used to tell ADO that the changes marked in the DataTable/DataSet have been processed through independent means. If you use the DataAdapter or generated TableAdapter Update method, "accept changes" is invoked for you on a row-by-row basis as ADO walks through the update process posting client-side changes to the server database.
There is an entirely different strategy (that I discuss in the book) that ignores the Update method entirely; it assumes that you have stored procedures that handle complex updates (multi-table related or cascading updates/deletes) without having to use ADO to do the low-level action commands for you. This approach uses INSERT SQL to add rows to the database and UPDATE and DELETE SQL to change or delete rows. But INSERT does not affect the local data store--the local DataTable or TableAdapter rowset--only the server-side data store. Keeping these two rowsets in sync is the issue. Again, there are several ways to accomplish this including use of replication.
You might benefit from my day-long workshop at DevTeach in Toronto on May 12th.
hth
--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
"jp2msft" <jp2msft@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:AC088AAF-880A-485F-B7F6-B7C81C9A172F@xxxxxxxxxxxxxxxxWhat page is that described in your book?
Is there a cut-and-dry way of showing me how that's done? Your book is
great, but 1000 pages just takes me too long to find what I need. (Are you
planning a Cookbook in the future?)
From what I understand, once the underlying structure has rows added or
modified, then I need to create a DataSet of changes made to the main
DataSet, updated my TableAdapter with these changes, accept the changes
through the main DataSet, then update TableAdapter again.
Does all of that sound confusing to you, too?
How is all of this better than just creating a new SqlConnection with an
INSERT Command? Microsoft did a lot of work with this, but I think it is
making things more difficult than they need to be. Is that just me?
"William Vaughn" wrote:
Yup, if it's data bound you just add a row to the DataTable (or structure)
to which it's bound.
--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
"jp2msft" <jp2msft@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9E28E7A7-A2D3-4514-BC96-BD2FAD0F1E43@xxxxxxxxxxxxxxxx
>A data-bound DataGridView is wonderfully simple to include with a >Windows
>Form.
>
> Now that all the data is there, how do I go about adding a new > record?
> When
> I tried, Visual Studio 2005 Pro gave me an InvalidOperationException,
> saying,
> "Rows cannot be programmatically added to the DataGridView's rows
> collection
> when the control is data-bound."
>
> Am I just not able to add a new record ever if I use a data-bound
> DataGridView, or do I need to follow some special steps to > un-data-bind
> it,
> add my data, then re-data-bind it?
.
- References:
- Re: Adding Rows to Data-Bound DataGridView
- From: jp2msft
- Re: Adding Rows to Data-Bound DataGridView
- From: William Vaughn
- Re: Adding Rows to Data-Bound DataGridView
- From: Miro
- Re: Adding Rows to Data-Bound DataGridView
- Prev by Date: Re: Adding Rows to Data-Bound DataGridView
- Next by Date: SQL Connection in detail
- Previous by thread: Re: Adding Rows to Data-Bound DataGridView
- Next by thread: Re: Adding Rows to Data-Bound DataGridView
- Index(es):
Relevant Pages
|