Wrox Programmer Forums
|
BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio
This is the forum to discuss the Wrox book ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solution by Vincent Varallo; ISBN: 9780470396865
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2009, 12:18 PM
Registered User
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch2 Viewstate implementation.

I have a query regarding the chapter 2 implementation of deleting records from the database. I'm critiquing the code as located on the wrox website, for chapter 2. Additionally to make it functional I added the LINQ/SQL dbml to interact with a MS SQL 2005 express server.

During the page_load event, the following linq query pulls in a record from the database:

ENTUserAccount userAccount = db.ENTUserAccounts.Single(ua =>
ua.WindowsAccountName == @”VARALLO1\VaralloMadison”);

However, if you click the delete function:

userAccount.ENTUserAccountId =
Convert.ToInt32(ViewState["ENTUserAccountId"]);
db.ENTUserAccounts.DeleteOnSubmit(userAccount);

This will delete the VaralloMadison entry from the table, as expected.

If you immediately click the INSERT button, this will cause a Page_load event. This is requested on page 35, and pasted below:

"6. Run the project again and click the Delete button on the Default.aspx page to get rid of the
second record.
7. Click the Insert button to insert the record."

However, because the page_load event contains a LINQ query hardcoded that requests a deleted user account you will get an InvalidOperationException because the userAccount LINQ will contain no results.

Am I doing something wrong? I'm slightly confused.
 
Old June 28th, 2009, 10:04 PM
Wrox Author
 
Join Date: Jan 2009
Posts: 73
Thanks: 0
Thanked 7 Times in 7 Posts
Default

Hello Sam I Am,
You can put a check in the page load to make sure the userAccount object is found. This code is for demo purposes only and later on in the book you'll see that adding, updating, deleting, and selecting of records is never done in the code behine page. Its always done in the Data Access Layer. The sample code was more to walk you through some of the options you have when using LINQ to SQL.
 
Old June 29th, 2009, 09:09 AM
Registered User
 
Join Date: Jun 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah, well that's fine. I assumed this book was a step by step walkthrough which would culminate in a complete project. This is why I took the code so literally- I realise that dealing with the error is trivial, I just assumed there would be no errors if the code was followed precisely.

I didn't realise it was just general principles. That explains why i'm having such a hard time understanding the BLL chapter..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch2, pg30 - page_load error -Sequence contains no elements joefoos BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 2 June 2nd, 2009 12:32 PM
CH2 p54-55 parse error. nodster BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 July 25th, 2007 11:16 AM
Exercise ch2, page 82 ssr All Other Wrox Books 2 September 10th, 2003 03:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.