Part 13- Insert data into MULTIPLE TABLES in an ASP.NET MVC application

Part 13- Insert data into MULTIPLE TABLES in an ASP.NET MVC application

Technotips Ashish

7 лет назад

88,770 Просмотров

In this video you will be able to insert your data into multiple table of database using Entity framework.

CONTACT US: [email protected]

SOCIAL :

Like TechnoTips official Page : http://facebook.com/technotipstutorial
Subscribe : http://youtube.com/user/aapkanigam

Get CODE HERE:
http://technotipstutorial.blogspot.com/2016/11/part-13-insert-data-into-multiple-table.html

INTRODUCTION :

This is part 13 of the video series .Please watch part 11 and 12 of the video series because in that tutorial I have just created a form using html helper .
Submitting a form and saving record in multiple table is very simple in asp.net mvc application. Use following step to insert data in database .

Step 1 : Use html.BeginForm and pass the method name ,controller name and form type .

Step 2: Put all elements inside html begin form .

Step 3: At Test controller create a overload method Index and pass EmployeeViewModel class as parameter.

Step 4 : When you submit a form then control goes to your given method name in html BeginForm ,so you can get all element data at that method parameter.

Step 5 : Create object of Employee class and and add properties from the parameter

Step 6 : Finally add this class to db context and call savechanges method .

Step 7 : you can get the latest id of emplyee .


Step 5 : Create object of Site class and and add properties value from the parameter properties value and latestEmpId

So in this way you can insert data into multiple table of database .
RECOMMENDATION:

Watch MODEL VIEW,CONTROLLER and bootstrap here

1. MODEL : Part 4- https://www.youtube.com/watch?v=yeUDYcvPF3A
2. VIEW :Part 3- https://www.youtube.com/watch?v=Pt2UoRFuT-Y
3. CONTROLLER :Part 2- https://www.youtube.com/watch?v=g2GbL4hPOMg
4.Bootstrap PopUp modal : https://www.youtube.com/watch?v=hKulrfOP_HI


TAGS :
how to create a - website
asp. net mvc
asp.net mvc interview questions
asp .net mvc tutorial
asp. net mvc 4
asp.net mvc 5 tutorial
asp net mvc developer
asp net mvc continuous integration
asp net mvc hosting
model view controller
jquery-ajax Post
$ ajax jquery
jquery ajax tutorial
viewbag
$controller
$model

Part 13 - Insert data into multiple table in an Asp.net MVC application
Part 13 - Insert data into multiple table in an Asp.net MVC application

Тэги:

#mvc #insert #asp.net #model #view #3d_desktop_windows_7 #samsung_galaxy_a9_unboxing #a8_2016 #microsoft_access_(software) #asp._net_mvc #how_to_create_a_-_website #asp.net_mvc_interview_questions #$controller #$model #asp.net_mvc_5_tutorial #model_view_controller #technotips_mvc #technotips_tutorial #ashish_mvc
Ссылки и html тэги не поддерживаются


Комментарии:

Lucas Rodrigues
Lucas Rodrigues - 13.05.2023 23:58

Good

Ответить
Farrukh Azad Pak
Farrukh Azad Pak - 08.01.2022 00:01

nice work dear friend

Ответить
Cameron Lodge
Cameron Lodge - 29.08.2021 23:59

Im really really battling with trying to update/edit this, can anyone help me...im so desperate for help

Ответить
NITISH UNVI
NITISH UNVI - 01.05.2021 18:21

Ashish, did it break ACID properties or not like somehow by any chance if system shuts down between the transaction of two table like if it add record only in employee table and shuts down so it creates extra or unecessary row in employee table correct me if i am wrong plz help me out with this if u have any solution

Ответить
Suraj Nautiyal
Suraj Nautiyal - 05.01.2021 10:11

Hi Ashish, I need your help.
You added 3rd table Site and made relationship with employee. Now how can we show site name with employee details when we click on any employee ?

Ответить
noman alam
noman alam - 05.12.2020 22:58

Your tutorial is the best to help the beginners, it helped me in my university project.

Ответить
Peter Mankge
Peter Mankge - 24.07.2020 23:03

thanks you Ashish, you doing a great work. Simple and straightforward

Ответить
Jayesh Shah
Jayesh Shah - 14.06.2020 09:28

@Technotips - Ashish
How come you are adding Test in url:"/Test..." I do not understand where have you defined it. Do you have this file downloadable?
How can we use ajax controller without defining <form>?

Ответить
AYO FOR YOU
AYO FOR YOU - 21.04.2020 01:26

this was really helpfull many thak's

Ответить
John Greenstreet
John Greenstreet - 13.04.2020 14:36

This was really helpful to me, Thank you so much - John, I will subscribe

Ответить
Martin C
Martin C - 01.04.2020 22:28

I was having a nightmare with a Uni project and this tutorial was everything I needed to overcome the problem. Many thanks

Ответить
avinash kadam
avinash kadam - 26.05.2019 06:52

How i can save data in multiple tabels in plane mvc no any entity model plz tell me.

Ответить
mohan raj
mohan raj - 08.05.2019 10:24

how to assign view page ?,give the sytax for html helper of two table in one view page

Ответить
Safwen
Safwen - 27.04.2019 01:27

NOW how to view them ?

Ответить
Alao Abiodun
Alao Abiodun - 20.03.2019 23:29

hi ashish love this tutorial but update the multiple tables is giving me error that primary key siteId__EmployeeId conflicting somehow please how did you do the database coz when i did my own database i created EmployeeId with identity(1,1) and so for SiteId

Ответить
Ronald
Ronald - 08.03.2019 10:38

Why are you calling the properties in your EmployeeViewModel //Custom attribute

Ответить
Liheab Treng
Liheab Treng - 10.02.2019 10:49

Hi I have a problem When insert data it has been inserted in to database but Ajax is not success when I debug it throw return undefined but data already go to database and when I debugged controller I saw it return some value I don't know what happened and I use only one table so I have been wrote code for a table

Ответить
Alao Abiodun
Alao Abiodun - 05.02.2019 12:08

Hi Ashish Please can you show how you create the relationship for the database because when i create my own i was having this following error on my database when i want to initialize first value into site table.
This is how i created my database:Please anyone to show me the answer if am wrong,
create table Site
(
SiteId int primary key NOT NULL,
EmployeeId int NOT NULL references Employee,
SiteName varchar(30) NOT NULL
);

insert into Site(SiteId,EmployeeId,SiteName) values(1,1005,'google.com');

This is the error i got:
Msg 547, Level 16, State 0, Line 8
The INSERT statement conflicted with the FOREIGN KEY constraint "FK__Site__EmployeeId__239E4DCF". The conflict occurred in database "MVCTutorial", table "dbo.Employee", column 'EmployeeId'.
The statement has been terminated.

Ответить
Narendar Singh
Narendar Singh - 07.11.2018 21:49

super

Ответить
sohil vaidya
sohil vaidya - 06.09.2018 08:17

Awesome Video....Keep posting other videos.....

Ответить
bntdgp
bntdgp - 28.08.2018 19:39

Please tell me how to disable back button of browser after inserting record.

Ответить
MICHAEL VENTURA
MICHAEL VENTURA - 07.08.2018 08:47

hello, i got this problem, could you explain to me please?

Se produjo una excepción de tipo 'System.InvalidOperationException' en System.Web.Mvc.dll pero no se controló en el código del usuario

Información adicional: El elemento ViewData con la clave 'DepartmentId' es de tipo 'System.Int32' pero debe ser de tipo 'IEnumerable<SelectListItem>'.

-------------------------------
the problem is located at the index view

@Html.DropDownListFor(model=>model.DepartmentId, ViewBag.DepartmentList as SelectList, "Select", new { @class="form-control"})

i have tried everything and nothing

Ответить
Sachin Bhalerao
Sachin Bhalerao - 04.08.2018 17:34

Very useful tutorial

Ответить
Sachin Bhalerao
Sachin Bhalerao - 04.08.2018 15:34

Very useful tutorial

Ответить
Sachin Bhalerao
Sachin Bhalerao - 04.08.2018 15:34

Very useful tutorial

Ответить
haydar M.Al-samawe
haydar M.Al-samawe - 16.06.2018 01:08

Hello Ashish first thank you for your support in this corse .. everything is so helpful .. i have problem .. to models with one to many relationship .. how i can update from one view for example first model is car details and second is car options many options so i have two kind of data in one view single and IEnumerable how i can fix that please

Ответить
Thuc Huu
Thuc Huu - 04.06.2018 20:45

Technotips - Ashish: Field EmployeeId in table Employee is primary key. How you add EmployeeId = 1005 ?

Ответить
Allan Agaba
Allan Agaba - 10.05.2018 11:57

Hi Ashish. This runs perfectly for me. However, I get an error when I try editing. Any tips?

Ответить
Navneil Naicker
Navneil Naicker - 03.05.2018 11:26

Thanks for awesome video

Ответить
Konz Z
Konz Z - 23.03.2018 04:03

How can you do the same without using entity framework?

Ответить
Attila
Attila - 21.03.2018 17:27

Ashish, you are an amazing guy in our world. I respect you. Your ASP .NET MVC tutorials really helped me a lot. Best Regards: Attila from Hungary, Europe

Ответить
sathish chowdary
sathish chowdary - 13.02.2018 08:24

Hi, This video is so helpful, can you update video on how to edit data in multiple tables. Thank you.

Ответить
Aya AbdelAziz
Aya AbdelAziz - 21.11.2017 17:38

Hi, I run this and it's working but every record inserted twice into employee and site tables can you help plz ??

Ответить
Priyanka Biswal
Priyanka Biswal - 12.11.2017 11:21

Hi. How are you inserting employee ID?

Ответить
SuperJamesII
SuperJamesII - 22.09.2017 20:29

Re-record and show all files missing to many steps or just add all file pages to your blog.

Ответить
Sanjay Kumar
Sanjay Kumar - 02.09.2017 16:54

Hi Ashis Getting Error while Inserting into "Site" Table ..Could you please help??

Ответить
Sanjay Kumar
Sanjay Kumar - 02.09.2017 15:05

Hi Ashis..a small Query.......Please help........Is there any relationship define between Employee and Site ID while generating Model class from Data Base as like previous(Between Employee and Department ) ?

Ответить
Jon Schneider
Jon Schneider - 16.08.2017 17:11

Hi Ashish, any thoughts on saving data into multiple SQL db tables which the data is derived from multiple HTML tables that are dynamically created? I'm currently getting all the data using a model and viewbags along with info the user will provide. My thought was to build array's of the data and pass it to the controller with json or ajax.

Ответить
Haroon Niaz
Haroon Niaz - 24.07.2017 12:18

Hi Ashish ,how you add Site table from database to MVCTutorialModel

Ответить
RAFIA ZAHEER
RAFIA ZAHEER - 12.06.2017 13:31

Error 1 Non-invocable member 'ProjectDataAccess.customer.email' cannot be used like a method. C:\Users\DeLL\documents\visual studio 2013\Projects\WebService1\WebService1\Controllers\CustomerController.cs 45 39 WebService1
need help..

Ответить
Waleed Abboud
Waleed Abboud - 17.05.2017 12:41

thank you very much

Ответить
veera muthu
veera muthu - 27.03.2017 16:47

Its very good tutorial. but i need to get div values view to contoller model class.. please help me.. Thank you..

Ответить
Pts Admin
Pts Admin - 23.03.2017 09:26

Hi, ashish its better to teach how to create the tables that which we are going to use this video, for ex: you used new table here called Sites, is there any relation b/w sites & Employees table?

Ответить
Ninja Developer
Ninja Developer - 09.02.2017 21:58

Excelente Tutorial

Ответить
fahad Hossain
fahad Hossain - 09.02.2017 01:45

in this vedio which one is forign key ? i mean only departmentID or both departmentID and EmployeeID?

Ответить
Krishna Parab
Krishna Parab - 21.01.2017 20:44

hi sir your video is vary great can you teach how to loagin 3rd party thr login in mvc application

Ответить