|
-
November 8th, 2008, 07:06 PM
#1
Update from a view
ADO.NET offers a great functionality which makes it very easy to implement databinding (two directional - read and write). Let`s assume that we have a DataSet with some simple DataTable tied with TableAdapter.
Here is what we have to do:
1) Create DataTable with the standard GetData method from the Adapter
2) Assign this datatable as binding source for our datagridview on UI
3) When user makes some changes in the datagridview, it is enough to call 'Update' method on the Adapter to transfer all changes into database.
This is very easy and fast to implement. However it does not work when our DataTable contains data from more than 1 physical tables from database (any joins in select clause).
Why is it impossible? The update method on tableAdapter does not generate at all. How to solve this?
Thank you very much for any help!
-
November 8th, 2008, 07:14 PM
#2
Re: Update from a view
The "write" methods (Insert,Update,Delete) can only be generated if the table is loaded via a means that:
1) is a single source
2) has a unique key
If EITHER of these are not true, it is impossible to automatically update the DB.
You MUST write the commands manually.
Note that for any "real" program this should ALWAYS be done, and all of the commands (including the "Load" command) should be calles to Stored Procedures in order to minimize both attack surface and potential for bugs.
[ie the application accound should NOT have any access to tables/views in the DB]
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions 
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
November 11th, 2008, 05:47 AM
#3
Re: Update from a view
The Adapter Wizard is Limited if you want to Update from a Join. Its because the Adapter does not know what record to update. Now its only limited to a Single table. That means you have to write the Data layer on your own now. Well i must say i started doing my Database work using Wizards and Microsoft has done a very good Job on them . But when you have to Update from a Join its a Problem. I have Written an Article that Solve the Problem, well not Solving the Problem , but Writting your code without using any Wizard.
check here
http://www.codeproject.com/KB/cs/N-Tier22.aspx
Hope this Helps
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|