1

How do insert data to a SQl Server 2008 database server using Entity Framework from a user input on a web application.

I added a new EF connection o my model. I am able to see all the mappings correctly.

I currently have the following in my view:

m.PhoneNumber) %>

and in my controller

 public ActionResult DialTone(Models.TelephoneModels telephone)
        {
            List<string> callType = new List<string>();
            callType.Add("Standard");
            callType.Add("Emergency");
            ViewData["TypeOfCalls"] = new SelectList(callType);
            if (!ModelState.IsValid)
            {
                return View("DialTone", telephone);
            }

            ViewData["Number"] = "You are currently connected to: " + telephone.PhoneNumber;

            using (LogEntities db = new LogEntities())
            {
                var log = db.Logs.Single(m => m.PhoneNumber == telephone.PhoneNumber);
                TryUpdateModel(log);
                db.SaveChanges();
            }


            return View();

I want to log all phone numbers (or strings) that the user inputs in the TextBox - phonenNumber into the database.

I created a LOG database table with a column called "PhoneNumber". I cant seem to figure out how to insert the data into the table.

Any ideas?

Thanks!

:)

1 Answer 1

1

I figure it out. I used:

 using (LogEntities db = new LogEntities())
            {
                Random random = new Random();
                Log p = new Log();
                p.ID = "400"; //Just a test
                p.PhoneNumber = telephone.PhoneNumber;
                db.AddToLogs(p);
                db.SaveChanges();
            }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.