Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

simple "SAVE" -- C# ASP.net MVC4 ?

Posted on 2013-11-06
2
Medium Priority
?
560 Views
Last Modified: 2013-11-06
Below runs, but does not insert the two new records.

How can I fix ?

Steps
 1. go to http://localhost:63802/C21/MAINT_WORK_REQ/test1
 2. below code runs
 3. refresh database
 4. below new records do NOT appear

----------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MWR.Models;

namespace MWR.Areas.C21.Controllers
{

    public class MAINT_WORK_REQController : Controller
    {
        private MVC_testEntities db = new MVC_testEntities();

        public ActionResult test1()
        {
            //create First Record
            MAINT_WORK_REQ mwr1 = new MAINT_WORK_REQ();
            mwr1.ProgramID = "1";
            mwr1.ProjectID = "1";
            mwr1.CreatedBy = "1";
            mwr1.LastModifiedBy = "1";
            mwr1.HSS_FWD = true;
            mwr1.HSS_INB = false;
            mwr1.HSS_OUTB = true;
            mwr1.BODYSTA_FWD = true;
            mwr1.BODYSTA_BOT = true;
            mwr1.BODYSTA_TOP = true;
            mwr1.EngineerRequired = true;

            //create Second Record
            MAINT_WORK_REQ mwr2 = new MAINT_WORK_REQ();
            mwr2.ProgramID = "1";
            mwr2.ProjectID = "1";
            mwr2.CreatedBy = "1";
            mwr2.LastModifiedBy = "1";
            mwr2.HSS_FWD = true;
            mwr2.HSS_INB = false;
            mwr2.HSS_OUTB = true;
            mwr2.BODYSTA_FWD = true;
            mwr2.BODYSTA_BOT = true;
            mwr2.BODYSTA_TOP = true;
            mwr2.EngineerRequired = true;

            //add both records
            db.SaveChanges();

            return View(db.MAINT_WORK_REQ.ToList());
        }
0
Comment
Question by:finance_teacher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 total points
ID: 39627534
Is there any sort of Add* method on your MVC_testEntities class?
0
 

Author Comment

by:finance_teacher
ID: 39627768
Below works

        public ActionResult test1()
        {
            //create First Record
            MAINT_WORK_REQ mwr1 = new MAINT_WORK_REQ();
            mwr1.ProgramID = "1";
            mwr1.ProjectID = "1";
            mwr1.CreatedBy = "1";
            mwr1.LastModifiedBy = "1";
            mwr1.HSS_FWD = true;
            mwr1.HSS_INB = false;
            mwr1.HSS_OUTB = true;
            mwr1.BODYSTA_FWD = true;
            mwr1.BODYSTA_BOT = true;
            mwr1.BODYSTA_TOP = true;
            mwr1.EngineerRequired = true;
            db.MAINT_WORK_REQ.Add(mwr1);
            db.SaveChanges();

            //create Second Record
            MAINT_WORK_REQ mwr2 = new MAINT_WORK_REQ();
            mwr2.ProgramID = "1";
            mwr2.ProjectID = "1";
            mwr2.CreatedBy = "1";
            mwr2.LastModifiedBy = "1";
            mwr2.HSS_FWD = true;
            mwr2.HSS_INB = false;
            mwr2.HSS_OUTB = true;
            mwr2.BODYSTA_FWD = true;
            mwr2.BODYSTA_BOT = true;
            mwr2.BODYSTA_TOP = true;
            mwr2.EngineerRequired = true;
            db.MAINT_WORK_REQ.Add(mwr2);
            db.SaveChanges();

            return View(db.MAINT_WORK_REQ.ToList());
        }
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question