Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 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 July 7th, 2017, 01:04 PM
N_B N_B is offline
Authorized User
 
Join Date: Feb 2016
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 14, Page 509

When I test inserting a new photo album, the record gets added to the table in the database just fine. And I see the ID in the table. But PhotoAlbumId in the query string always shows 0.

http://localhost:50829/ManagePhotoAlbum?PhotoAlbumId=0

Any ideas at what to look at?
Note: there is no space after the ? in the query string below. It just appears that way in this forum post. Don't know why.


Public Sub DetailsView1_InsertItem()

Dim photoAlbum As New PHOTOALBUM()

TryUpdateModel(photoAlbum)

If ModelState.IsValid Then
Using myEntities As New PlanetWroxEntities()
myEntities.PHOTOALBUMs.Add(photoAlbum)
myEntities.SaveChanges()
End Using

Response.Redirect(String.Format("ManagePhotoAlbum? PhotoAlbumId={0}", photoAlbum.ID.ToString()))
End If

End Sub
 
Old July 9th, 2017, 03:38 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Is ID the column in the database that has an identity? I.e. is that the column that auto-increments? Did you maybe make the column an identity in the database after you created the model? In that case, you have to regenerate the model as it may not be aware that the database generates the values for it.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 10th, 2017, 01:37 PM
N_B N_B is offline
Authorized User
 
Join Date: Feb 2016
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, the ID column does auto-increment. It works fine in the database. The record gets created with the next number for the ID. I also just executed "Update Model from Database" and tried it again but it didn't help.
 
Old July 10th, 2017, 03:28 PM
N_B N_B is offline
Authorized User
 
Join Date: Feb 2016
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got it. I noticed in the model that the StoreGeneratedPattern property for the ID column was set to None. So I changed this to Identity and it works now. I'm using Oracle so it seems that the integration with VS is not so great as compared with SQL Server. I assume with SQL Server, this StoreGeneratedPattern property is automatically set?

Anyway .... it's working now. Thank you for your response. Much appreciated.

And this is a really good book by the way.
 
Old July 13th, 2017, 03:41 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Ah, yes, that explains it. Didn't know you were using Oracle.

>> I assume with SQL Server, this StoreGeneratedPattern property is automatically set?

Yep.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14, pp 508 - 509 Aldaron BOOK: Beginning ASP.NET 4.5.1 : in C# and VB 1 August 16th, 2016 09:38 PM
Chapter 14 - page 503 (Try it out) Ronin_PS BOOK: Beginning ASP.NET 4.5 : in C# and VB 4 March 20th, 2015 10:58 AM
Chapter 14 - Try it out - page 500 jrwhite BOOK: Beginning ASP.NET 4 : in C# and VB 0 August 31st, 2012 02:19 PM
Chapter 1 page 14 kermit1965 BOOK: Professional ASP.NET MVC 2 6 October 12th, 2010 10:10 AM
Chapter 13 p. 509 arienlee BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 July 31st, 2004 07:19 AM





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