|
 |
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 .
|
 |
|
|
 |

July 7th, 2017, 01:04 PM
|
Authorized User
|
|
Join Date: Feb 2016
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|

July 9th, 2017, 03:38 PM
|
 |
Wrox Author
Points: 71,561, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,001
Thanks: 79
Thanked 1,573 Times in 1,550 Posts
|
|
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
|

July 10th, 2017, 01:37 PM
|
Authorized User
|
|
Join Date: Feb 2016
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

July 10th, 2017, 03:28 PM
|
Authorized User
|
|
Join Date: Feb 2016
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

July 13th, 2017, 03:41 AM
|
 |
Wrox Author
Points: 71,561, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,001
Thanks: 79
Thanked 1,573 Times in 1,550 Posts
|
|
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
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |
All times are GMT -4. The time now is 09:31 PM.
|