View Single Post
  #11 (permalink)  
Old January 24th, 2012, 05:05 PM
leeWozyWarren leeWozyWarren is offline
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
Default

I tried to make some changes but was getting no where so I decided to recreate the page complete with a new table with a reduced amount of text box's. I also remade the EF .edmx file from scratch. This time I get no wriggly lines under the code showing me that something doesn't work. The new page is called Test01.aspx.

I completed the initial Page_Load code and then tested it. It worked. The text boxes took data from the database correctly with no errors. Then I added the Button_Code and that is where it fell over when I tried to browse the page.

Below is the new code behind.

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DistanceModel;

public partial class test01 : System.Web.UI.Page

{
    int _id = -1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString.Get("MileageId")))
        {
            _id = Convert.ToInt32(Request.QueryString.Get("MileageId"));
        }
        if (!Page.IsPostBack && _id > -1)
        {
            using (distanceEntities myEntities = new distanceEntities())
            {
                var Mileage = (from r in myEntities.Mileages
                               where r.MileageId == _id
                               select r).SingleOrDefault();
                if (Mileage != null)
                {
                    MondayTotal.Text = Mileage.M_To_Total.ToString();
                    TuesdayTotal.Text = Mileage.T_To_Total.ToString();
                    WednesdayTotal.Text = Mileage.W_To_Total.ToString();
                    ThursdayTotal.Text = Mileage.T_To_Total.ToString();
                }
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        using (distanceEntities myEntities = new distanceEntities())
        {
            
            Mileage myMileage;

            if (_id == -1) //Insert new item
            {
                myMileage = new Mileage();

                myEntities.AddToMileages(myMileage);
            }
            else // update new item
            {
                myMileage = (from r in myEntities.Mileages
                             where r.MileageId == _id
                             select r).Single();
            }

            myMileage.M_To_Total = Convert.ToInt32(MondayTotal.Text);
            myMileage.T_To_Total = Convert.ToInt32(TuesdayTotal.Text);
            myMileage.W_To_Total = Convert.ToInt32(WednesdayTotal.Text);
            myMileage.T_To_Total = Convert.ToInt32(ThursdayTotal.Text);

            myEntities.SaveChanges();
            Response.Redirect("Choose.aspx");
        }
    }
}
This is the error the browser shows:


Code:
Compilation Error 
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: CS1502: The best overloaded method match for 'DistanceModel.distanceEntities.AddToMileages(DistanceModel.Mileage)' has some invalid arguments

Source Error:

 

Line 45:                 myMileage = new Mileage();
Line 46: 
Line 47:                 myEntities.AddToMileages(myMileage);
Line 48:             }
Line 49:             else // update new item
...
Reply With Quote