Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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 November 22nd, 2012, 12:58 PM
Authorized User
 
Join Date: Oct 2012
Posts: 27
Thanks: 4
Thanked 2 Times in 2 Posts
Default Chapter 14, page 510 VB: Picture class is not recognized

After doing the tryout (5-6 times), when opening ManagePhotoAlbum.aspx, I always get this error:
Code:
 Compiler Error Message: BC30002: Type 'Picture' is not defined.
...
Line 8:      Dim myPicture As Picture = CType(e.Entity, Picture)   <<line in red>>
...
In the code, by hovering over "As Picture", I got the following "Error Correction Options": "Imports PlanetWroxModel", which I accept. In fact looking at the Source/Chapter 14 corresponding file, I see that this statement is included there.
However, after correction, I got another error:

For the EntityDataSource, either Type or DbType (but not both) must be specified for each Parameter.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: For the EntityDataSource, either Type or DbType (but not both) must be specified for each Parameter.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[InvalidOperationException: For the EntityDataSource, either Type or DbType (but not both) must be specified for each Parameter.]
System.Web.UI.WebControls.EntityDataSourceView.Exe cuteSelect(DataSourceSelectArguments arguments) +738
System.Web.UI.DataSourceView.Select(DataSourceSele ctArguments arguments, DataSourceViewSelectCallback callback) +21
System.Web.UI.WebControls.DataBoundControl.Perform Select() +143
System.Web.UI.WebControls.ListView.PerformSelect() +113
System.Web.UI.WebControls.BaseDataBoundControl.Dat aBind() +74
System.Web.UI.WebControls.BaseDataBoundControl.Ens ureDataBound() +66
System.Web.UI.WebControls.ListView.CreateChildCont rols() +55
System.Web.UI.Control.EnsureChildControls() +102
System.Web.UI.Control.PreRenderRecursiveInternal() +42
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496


In CS the tryout worked well, however I want to make it work in VB too. Can anyone help me? Thanks.
 
Old November 22nd, 2012, 03:44 PM
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,

The Imports for the namespace makes sense; without it .NET doesn't know where to find the Picture type.

About the other error, take a look at this:

Quote:
For the EntityDataSource, either Type or DbType (but not both) must be specified for each Parameter.
Do your parameters have a type property? Have you tried comparing the VB code with the C# version, or the VB code with mine?

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 November 22nd, 2012, 08:20 PM
Authorized User
 
Join Date: Oct 2012
Posts: 27
Thanks: 4
Thanked 2 Times in 2 Posts
Default

In fact, I had seen the suggested post and I verified in the query that the type for the new parameter, PhotoAlbumId is Int32. There's no place where to declare a type for Picture.
I did compare my code with the C# code: the only difference (except C# syntactics) is that C# is showing an "using PlanetWroxModel" statement rather than an "import PlanetWroxModel", however, when I put "Import PlanetWroxModel" in my VB code I got error too.
I did compare my code with the "Source\Chapter 14" code, even cut and overwrote it into my code, but it doesn't do any good.
One difference is that the ManangePhotoAlbum class appears as "_ManangePhotoAlbum" in the resource code, which is not recognized as a class in my code (got that error) if I change it.
Another difference is my page has "Inherits System.Web.UI.MasterPage", rather than "Inherits BasePage" as in the "Source\Chapter 14" code, but changing it makes no difference either.
Also, as a mater of fact, both in my code and in "Source\Chapter 14" code, the Frontend.aspx.vb has has "Inherits System.Web.UI.MasterPage", rather than "Inherits BasePage", meaning that the change to BasePage was not required anywhere in the book. In the tryout it is required to use the normal master page, which is Frontend.
The only thing which works is to replace the whole ManangePhotoAlbum.aspx and ManangePhotoAlbum.aspx.vb in my site. However, I need to know where the error is, as my purpose is to learn ASP...
So, my question is, why the Picture class is not created. I did the tryout at least five times, with the same result.
A discrepancy with the book is at page 506, "4.", when you edit the "Where" property: the "Parameter source" "Query string" appears in the picture, but it is not indicated that it must be selected, however, you have to.
Also, at page 511, first line, it there's a statement, "OnInserting="EntitydataSource1_Inserting", which doesn't appear nor in my code, neither in "Source\Chapter 14" code, but adding it to my code doesn't change anything.
And unrelated to above, I have an errata suggestion:
page 500, section 7. "...check off..." should be changed to simple "check", as the checkbox does not have to be left unchecked, as shown in the picture. With the checkbox unchecked, the tryout cannot be continued.

Please help me further on.
Thanks.
 
Old November 23rd, 2012, 09:23 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,

Quote:
There's no place where to declare a type for Picture.
Picture is not a parameter so you don't need to specify a type. Instead , you need to bring it in scope in the Code Behind using an Imports statetment.

Quote:
One difference is that the ManangePhotoAlbum class appears as "_ManangePhotoAlbum" in the resource code, which is not recognized as a class in my code (got that error) if I change it.
Another difference is my page has "Inherits System.Web.UI.MasterPage", rather than "Inherits BasePage" as in the "Source\Chapter 14" code, but changing it makes no difference either.
This seems to suggest you created a Master Page instead of a regular page. ManangePhotoAlbum should be a regular Web Form based on your custom template. This may be part of the problem.

Quote:
Also, as a mater of fact, both in my code and in "Source\Chapter 14" code, the Frontend.aspx.vb has has "Inherits System.Web.UI.MasterPage", rather than "Inherits BasePage", meaning that the change to BasePage was not required anywhere in the book.
That's correct. Frontend is a Master Page and as such inherits from MasterPage. Your regular pages (both standard web forms as well as the ones you create based on your custom template) should inherit BasePage. The change you made to all pages in the site should have been applied to Pages (Web Forms) only, and not to the MasterPages that should continue to inherit MasterPage.

Quote:
In the tryout it is required to use the normal master page, which is Frontend.
The only thing which works is to replace the whole ManangePhotoAlbum.aspx and ManangePhotoAlbum.aspx.vb in my site. However, I need to know where the error is, as my purpose is to learn ASP...
This could be caused by the fact you created a Master Page, not a regular page / web form.

Quote:
A discrepancy with the book is at page 506, "4.", when you edit the "Where" property: the "Parameter source" "Query string" appears in the picture, but it is not indicated that it must be selected, however, you have to.
This is covered by the text "and then fill in the Expression Editor dialog box as shown in Figure 14-13.".

Quote:
Also, at page 511, first line, it there's a statement, "OnInserting="EntitydataSource1_Inserting", which doesn't appear nor in my code, neither in "Source\Chapter 14" code, but adding it to my code doesn't change anything.
That's from the C# example. I pointed out the differences between C# and VB (C# uses On in Markup, VB uses Handles in the Code Behind) here and there in the book.

Quote:
And unrelated to above, I have an errata suggestion:
page 500, section 7. "...check off..." should be changed to simple "check", as the checkbox does not have to be left unchecked, as shown in the picture. With the checkbox unchecked, the tryout cannot be continued.
Confusingly enough, "to check off" means "to check": http://www.thefreedictionary.com/check+off ;-)

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 November 24th, 2012, 11:39 AM
Authorized User
 
Join Date: Oct 2012
Posts: 27
Thanks: 4
Thanked 2 Times in 2 Posts
Default The INSERT statement conflicted with the FOREIGN KEY constraint

Thank you very much for your ample answers.
In fact, I haven't created ManagePhotoAlbum.aspx a new master page (the extension confirms it), but as a new web form, rather than a MyBasePage. Simply changing Inherits to BasePage, or re-creating the page as a MyBasePage didn't resolve the issue. Which was also weird, was the fact that if I added "Import PlanetWorxModel, "Picture" was recognized, but "e" wasn't recognized any more. That suggested me that I have to go back farther, so I re-created both NewPhotoAlbum.aspx and ManagePhotoAlbum.aspx, based on MyBasePage. Now I have no more errors on "Picture" or "e" and everything looked allright, however, I got another error when hit Insert for the new album:
------------------------------------------------------------------------------------------T
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Picture_PhotoAlbum". The conflict occurred in database "C:\BEGASPNETVB\SITEVB\APP_DATA\PLANETWROX.MDF ", table "dbo.PhotoAlbum", column 'Id'.
The statement has been terminated.
-------------------------------------------------------------------------------------------
I verified the database, the entity and the "where" clause, recreated the relations and updated the entity, however with no effect on the error.
Could you please help me with this issue?
Thanks.
 
Old November 24th, 2012, 11:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You typically get this error when you're passing an invalid ID of the album to the page. This could be the case when you open it directly, or when you use a different query string parameter in the call to Response.Redirect in the NewAlbum page than the one in the manage album page.

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 November 25th, 2012, 11:47 AM
Authorized User
 
Join Date: Oct 2012
Posts: 27
Thanks: 4
Thanked 2 Times in 2 Posts
Default

Thank you for your help.
I resolved all the issues by re-creating the pages. I had certainly missed something before, but troubleshooting looked much more tiresome than the re-work, especially because often there's a discrepancy between how one perceives the error message and the real cause.
By the way, I tried to troubleshoot by putting a break point in the ManagePhotoAlbum.aspx.vb, EntityDataSource1_Inserting code, but the execution never stopped. I know the code was run because I inserted a vaule which was correctly read. In my web.config file, I have <compilation debug="true"....> and do not get any message when press F5, so the debugging should work.
Thank you again, your help is very much appreciated.
 
Old November 25th, 2012, 05:31 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

>> but the execution never stopped.

That's odd. Are you sure it fires indeed? Does the method have the Handles keyword? Do other breakpoints work OK?

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 - p.510, step #13 Tulsi BOOK: Beginning ASP.NET 4 : in C# and VB 4 October 25th, 2012 12:56 PM
Ch 14: Try it Out p. 510 - error 'PlanetWroxModel.Picture' is a 'type' jayinatlanta BOOK: Beginning ASP.NET 4 : in C# and VB 2 November 5th, 2011 09:50 AM
Chapter 1 page 14 kermit1965 BOOK: Professional ASP.NET MVC 2 6 October 12th, 2010 10:10 AM
CSS class not recognized in ContactForm.ascx avi1 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 October 11th, 2010 06:05 AM
Chapter 14 page 491 Will BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 April 25th, 2009 04:52 AM





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