![]() |
Chapter 15 Error
Hi,
I am trying the Try it out in Ch15 with my own code. The Page_Load works fine, but the Save_Button_Click throws errors around the following: Code:
myEntities.AddToMileages(myMileage); Code:
.Single(); Code:
M_St_To_Miles Code:
using System; Regards Lee |
Hi Lee,
Does _id ever get a valid value? Imar |
Hi Imar,
I thought that _id was a variable! I have no actual data using _id in a data or view. Lee |
It is a variable, which should get a value from the query string. Does it successfully get a value?
Imar |
Hi Imar,
_id in the page_load gets a value from a query string when a user clicks a link in an other page. But the _id in the button_click doesn't get a value for "insert a new item" but it should be able to take a value for an update from the query string. Or doesn't it? |
Yes. Judging from your description, Single() returns null, which seems to imply the item you're editing does not exist in the database.
Did you try debugging your code to see where it breaks exactly? Cheers, Imar |
These are the errors that the debugging throws up...
Code:
Error 1 'MileageModel.MileageEntities' does not contain a definition for 'AddToMileage' and no extension method 'AddToMileage' accepting a first argument of type 'MileageModel.MileageEntities' could be found (are you missing a using directive or an assembly reference?) C:\BegASPNET\mileage\Mileage.aspx.cs 82 28 C:\BegASPNET\mileage\ Code:
Error 2 Cannot implicitly convert type 'MileageModel.Mileage' to 'Mileage' C:\BegASPNET\mileage\Mileage.aspx.cs 88 39 C:\BegASPNET\mileage\ Code:
Error 4 'Mileage' does not contain a definition for 'M_Fi_To_Miles' and no extension method 'M_Fi_To_Miles' accepting a first argument of type 'Mileage' could be found (are you missing a using directive or an assembly reference?) C:\BegASPNET\mileage\Mileage.aspx.cs 91 23 C:\BegASPNET\mileage\ Code:
Error 5 'Mileage' does not contain a definition for 'M_St_Fr_Miles' and no extension method 'M_St_Fr_Miles' accepting a first argument of type 'Mileage' could be found (are you missing a using directive or an assembly reference?) C:\BegASPNET\mileage\Mileage.aspx.cs 93 23 C:\BegASPNET\mileage\ Code:
Error 6 'Mileage' does not contain a definition for 'M_Fi_Fr_Miles' and no extension method 'M_Fi_Fr_Miles' accepting a first argument of type 'Mileage' could be found (are you missing a using directive or an assembly reference?) C:\BegASPNET\mileage\Mileage.aspx.cs 94 23 C:\BegASPNET\mileage\ |
I'm not sure what these actually mean!
|
You get these at development time, not at run-time right? That means something is wrong.... ;-)
I can see a few possible reasons for this problem: 1. Your ASPX page is called Mileage as well. This may or may not cause a name conflict with your mileage class. Try create a new file with a new name and copy in the code (or rename the file, and the reference to Mileage in the markup and code behind.) 2.Something is wrong with your model so it doesn't compile. Try commenting out the failing code in this ASPX page, cose all open files, and press Ctrl+Shift+B to rebuild all code. Do you still get errors? Imar |
Thanks Imar. I will try 1 and 2 and see what happens. What is the difference between development and run-time?
|
All times are GMT -4. The time now is 04:38 AM. |
Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.