Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : 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 February 21st, 2016, 04:56 AM
Registered User
 
Join Date: Feb 2016
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 14 - EntitySqlException

I receive the following error when I try and view the ManagePhotoAlbum.aspx file in the browser:


System.Data.EntitySqlException: 'PhotoAlbumId' is not a member of type 'PlanetWroxModel.PhotoAlbum' in the currently loaded schemas. Near simple identifier, line 6, column 4.

Any clues on what this means and how to go about resolving it is greatly appreciated.
 
Old February 21st, 2016, 06:03 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

If you follow along with the book, the error message is correct, and PhotoAlbum would not have a property called PhotoAlbumId. but only one called Id.

The question is: why does your code reference
PhotoAlbumId which is hard to answer without seeing your code for
ManagePhotoAlbum.aspx.

Cheers,

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 February 23rd, 2016, 07:12 AM
Registered User
 
Join Date: Feb 2016
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for taking the time to help me resolve my issue. Here is the code for ManagePhotoAlbum.aspx, as suggested:

Code:
 <%@Page Title="Manage Photo Album" Language="VB" MasterPageFile="~/MasterPages/Management.master" AutoEventWireup="false" CodeFile="ManagePhotoAlbum.aspx.vb" Inherits="ManagePhotoAlbum" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
    <asp:ListView ID="ListView1" runat="server" DataKeyNames="Id" 
        DataSourceID="EntityDataSource1" InsertItemPosition="LastItem">
               
          <InsertItemTemplate>
            <li style="">
            Description:
                <asp:TextBox ID="DescriptionTextBox" runat="server" 
                    Text='<%# Bind("Description") %>' />
                <br />
            ToolTip:
                <asp:TextBox ID="ToolTipTextBox" runat="server" Text='<%# Bind("ToolTip") %>' />
                <br />
            ImageUrl:
                <asp:TextBox ID="ImageUrlTextBox" runat="server" 
                    Text='<%# Bind("ImageUrl") %>' />
                <br />
                <asp:Button ID="InsertButton" runat="server" CommandName="Insert" 
                    Text="Insert" />
                <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" 
                    Text="Clear" />
            </li>
        </InsertItemTemplate>
        
        <ItemTemplate>
            <li style="">
                Description:
                <asp:Label ID="DescriptionLabel" runat="server" 
                    Text='<%# Eval("Description") %>' />
                <br />
                ToolTip:
                <asp:Label ID="ToolTipLabel" runat="server" Text='<%# Eval("ToolTip") %>' />
                <br />
                ImageUrl:
                <asp:Label ID="ImageUrlLabel" runat="server" Text='<%# Eval("ImageUrl") %>' />
                <br />
                <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" 
                    Text="Delete" />
            </li>
        </ItemTemplate>
        <LayoutTemplate>
            <ul class = "ItemContainer">
               <li runat="server" id="itemPlaceholder" />
            </ul>
        </LayoutTemplate>
        
    </asp:ListView>
    
    <asp:EntityDataSource ID="EntityDataSource1" runat="server" 
        ConnectionString="name=PlanetWroxEntities1" 
        DefaultContainerName="PlanetWroxEntities1" EnableDelete="True" 
        EnableFlattening="False" EnableInsert="True" EntitySetName="PhotoAlbums" 
        Where="it.PhotoAlbumId = @photoAlbumId">
        <WhereParameters>
            <asp:Parameter Name="PhotoAlbumId" Type="Int32" />
        </WhereParameters>
    </asp:EntityDataSource>
</asp:Content>
Again, many thanks for your help
 
Old February 24th, 2016, 05:01 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 that explains it. Your Where clause is wrong, and your Where parameter is off.

The Where clause should read:

Where="it.PhotoAlbum.Id = @photoAlbumId"

As it filters the ID of the PhotoAlbum based in the photoAlbumId parameter.

That param should then look like this:

<WhereParameters>
<asp:QueryStringParameter Name="PhotoAlbumId" QueryStringField="PhotoAlbumId" Type="Int32" />
</WhereParameters>

Hope this helps,

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 February 24th, 2016, 05:19 AM
Registered User
 
Join Date: Feb 2016
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for your continued time and assistance. I fixed the where clause, as directed, but now a new error is thrown:

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30506: Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

Source Error:


Line 4: Inherits System.Web.UI.Page
Line 5:
Line 6: Protected Sub EntityDataSource_Inserting(sender As Object, e As System.Web.UI.WebControls.EntityDataSourceChanging EventArgs) Handles EntityDataSource1.Inserting
Line 7: Dim photoAlbumId As Integer =
Line 8: Convert.ToInt32(Request.QueryString.Get("PhotoAlbu mId"))


Source File: C:\BegASPNET\Source\Chapter 07\ManagePhotoAlbum.aspx.vb Line: 6

The code for ManagePhotoAlbum.aspx.vb reads:

Code:
 
Imports PlanetWroxModel

Partial Class ManagePhotoAlbum
    Inherits System.Web.UI.Page

    Protected Sub EntityDataSource_Inserting(sender As Object, e As System.Web.UI.WebControls.EntityDataSourceChangingEventArgs) Handles EntityDataSource1.Inserting
        Dim photoAlbumId As Integer =
            Convert.ToInt32(Request.QueryString.Get("PhotoAlbumId"))
        Dim myPicture As Picture = CType(e.Entity, Picture)
        myPicture.PhotoAlbumID = photoAlbumId

    End Sub
End Class
Any ideas? Again, thanks so much. Shane
 
Old February 24th, 2016, 09:22 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Could there be a mismatch between your Markup and Code Behind? Based on what you posted there's no explanation for this error but your code and markup may have changed by now. When posting questions like this please:

a) Google for the error message first

b) if that doesn't help, provide all the relevant code. In this case that would be the markup as well as the code behind.

Cheers,

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
help in chapter 14 please nawar youssef BOOK: Beginning PHP 5.3 3 October 27th, 2011 11:36 PM
Chapter 14, first 'Try It Out' alharlow BOOK: Beginning ASP.NET 4 : in C# and VB 5 March 18th, 2011 05:00 AM
chapter 14 vthunder70 BOOK: Beginning ASP.NET 2.0 and Databases 2 October 3rd, 2007 02:11 PM
Chapter 14 example pkumar@ech BOOK: Professional Jakarta Struts 0 November 15th, 2006 09:10 AM
Chapter 14 JonG BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 1 March 21st, 2006 10:04 PM





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