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

June 24th, 2014, 01:32 PM
|
|
Registered User
|
|
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Insert & Edit modes not available
Hello in the exercise in chapter 14 "A simple EntityDataSource Application" - I get to step 8 without problems but when I look at the smart tasks panel for the detailsview - I don't see the option to insert or edit. I'm not sure what is causing this please can you advise?
Code:
<%@ Page Title="Create New Photo Album" Language="VB" MasterPageFile="~/MasterPages/FrontEnd.master" AutoEventWireup="false" CodeFile="NewPhotoAlbum.aspx.vb" Inherits="NewPhotoAlbum" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id" DataSourceID="EntityDataSource1" DefaultMode="Insert" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" InsertVisible="False" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
</Fields>
</asp:DetailsView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server" ConnectionString="name=PlanetWroxEntities" DefaultContainerName="PlanetWroxEntities" EnableFlattening="False" EntitySetName="PhotoAlbums">
</asp:EntityDataSource>
</asp:Content>
Code:
Imports PlanetWroxModel
Partial Class NewPhotoAlbum
Inherits System.Web.UI.Page
Protected Sub EntityDataSource1_Inserted(sender As Object, e As EntityDataSourceChangedEventArgs) Handles EntityDataSource1.Inserted
If (e.Entity IsNot Nothing) Then
Dim myPhotoAlbum As PhotoAlbum = CType(e.Entity, PhotoAlbum)
Response.Redirect(String.Format("ManagePhotoAlbum.aspx?PhotoAlbumId={0}", myPhotoAlbum.Id.ToString()))
End If
End Sub
End Class
Thanks
|
|

June 25th, 2014, 09:49 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Did you set the Id column as a primary key and Identity in the database before you created the EF diagram?
Imar
|
|

June 25th, 2014, 02:57 PM
|
|
Registered User
|
|
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Primary Key & ID
Hi Imar,
Yes the primary key field shows on both the tables in the edmx file and the two tables are joined as they should be.
One has int and the other has int 32 though - maybe that is the problem?
Looking in the database both ID fields are set to int.
Thanks
To be sure I refreshed the ef - still no dice.
Here are the sql scripts :
Code:
USE [PlanetWrox]
GO
/****** Object: Table [dbo].[Picture] Script Date: 25/06/2014 20:28:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Picture](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Description] [nvarchar](300) NOT NULL,
[ToolTip] [nvarchar](50) NOT NULL,
[ImageUrl] [nvarchar](200) NOT NULL,
[PhotoAlbumId] [int] NOT NULL,
CONSTRAINT [PK_Picture] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Picture] WITH CHECK ADD CONSTRAINT [FK_Picture_PhotoAlbum] FOREIGN KEY([PhotoAlbumId])
REFERENCES [dbo].[PhotoAlbum] ([Id])
GO
ALTER TABLE [dbo].[Picture] CHECK CONSTRAINT [FK_Picture_PhotoAlbum]
GO
Code:
USE [PlanetWrox]
GO
/****** Object: Table [dbo].[PhotoAlbum] Script Date: 25/06/2014 20:27:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[PhotoAlbum](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](100) NOT NULL,
CONSTRAINT [PK_PhotoAlbum] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Last edited by bedsingar; June 25th, 2014 at 03:29 PM..
|
|

June 29th, 2014, 07:25 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Have you tried redoing the exercise? Also, do you see a blue "Refresh schema" link on the Smart Tasks panel or data source configurations screen? That may help in refreshing the schema so VS understands that Inserts and Updates are supported.
If that doesn't help, can you make a ZIP file available of the website and database somewhere online? Then I'll see if I can figure it out.
Cheers,
Imar
|
|

June 29th, 2014, 02:11 PM
|
|
Registered User
|
|
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks - Yes I've just run through again from the stage of creating the SQL diagram. Still no luck though. How do I export what you need to see?
I assume you need a copy of the database and the website too? - How do I export the website?
Also yes there is a refresh link - but all it does is bring the ID field back to visible.
Thanks
Quote:
Originally Posted by Imar
Have you tried redoing the exercise? Also, do you see a blue "Refresh schema" link on the Smart Tasks panel or data source configurations screen? That may help in refreshing the schema so VS understands that Inserts and Updates are supported.
If that doesn't help, can you make a ZIP file available of the website and database somewhere online? Then I'll see if I can figure it out.
Cheers,
Imar
|
|
|

June 29th, 2014, 02:33 PM
|
|
Registered User
|
|
Join Date: Jun 2014
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ah ok I've got it ...
I miss understood point 7 in the exercise "you need insert behaviour, so check off the Enable Automatic Inserts check box" when configuring the data source.
I copied the screenshot in 14-11 and left the box unchecked.
Having tried checking the box the option now appears in smart tasks.
Thanks though.
|
|

June 29th, 2014, 03:50 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Ah, I see. That explains it.
Cheers,
Imar
|
|
 |
|