Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 7th, 2017, 01:04 PM
N_B N_B is offline
Authorized User
Points: 103, Level: 2
Points: 103, Level: 2 Points: 103, Level: 2 Points: 103, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old July 9th, 2017, 03:38 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 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!
Reply With Quote
  #3 (permalink)  
Old July 10th, 2017, 01:37 PM
N_B N_B is offline
Authorized User
Points: 103, Level: 2
Points: 103, Level: 2 Points: 103, Level: 2 Points: 103, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #4 (permalink)  
Old July 10th, 2017, 03:28 PM
N_B N_B is offline
Authorized User
Points: 103, Level: 2
Points: 103, Level: 2 Points: 103, Level: 2 Points: 103, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
  #5 (permalink)  
Old July 13th, 2017, 03:41 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,948
Thanks: 79
Thanked 1,555 Times in 1,532 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!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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



All times are GMT -4. The time now is 12:56 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.