View Single Post
  #1 (permalink)  
Old December 2nd, 2015, 01:27 PM
mbedell1@msn.com mbedell1@msn.com is offline
Registered User
Points: 55, Level: 1
Points: 55, Level: 1 Points: 55, Level: 1 Points: 55, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2014
Location: Colorado
Posts: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Default Chap 17 Code1 Books Not saving

All,

I have not seen this problem from anyone else, or errata on the problem so I'm entering it here for anyone who is trying to get the code working.

In Code1 the Books.cs file seems to have been copied from a more advanced version of the code that allows for more data to be collected such as "Price" and "Publisher". However, the table in the database doesn't support those values; only "Title" and "Author". To correct the Books.cs file so that it will save updates made in the table, make the following changes:

1. Do a search for all instances of "Price" and "Publisher" and remove them, (don't forget to remove commas that are associated with these values along with any other identifiers such as "string"). In the ExecuteCommand function there are additional lines of code associated with these values that should also be removed. If you wish, you can just rem them out if your not sure which lines to keep and which to get rid of; though it should be fairly obvious.

2. Locate all instances of "AuthorID" and change them to "Author". In addition change the "int" identifier for "Author" to "string" as this is not an integer value. There is one location, in the ExecuteCommand function where "SqlDbType.int" should be changed to "SqlDbType.VarChar" as SQL doesn't use "string".

3. In ExecuteCommand, There are two references to SqlParameters (an array) an they are being established as a size of 4 and 5. These need to be reduced by two since you are no longer trying to send "Price" and "Publisher".

That's all you should need to do. Run the web page and you should now be able to Edit the data and perform an Update. Let me know if this still doesn't work or you're having other problems.

Mark