ASP.NET MVC Data Access in C# – The complete data path from database to display and back


Full courses:
Source Code:
Newsletter signup:

Tutorials are excellent at teaching you about a piece of the overall development puzzle but sometimes you want to take a step back and look at the bigger picture. That way you can see where those puzzle pieces you have been collecting fit into place. This video is going to be that bigger picture overview. We are going to build a small demo of an MVC application and its accompanying database. We will set up a form to collect data, capture that data, and put it into our database. We will then get that data back out of our database and display it on another form. The goal is to show the data access process from beginning to end in ASP.NET MVC. This won’t be a full application and we won’t complete the full process, since we won’t be putting this in source control, we won’t be deploying this application, and we won’t be setting up authentication.


Xem Thêm Bài Viết Khác:


  1. do you have a course that covers OWASP Top 10? I saw the @Html.AntiForgeryToken() razor code in this presentation (it was great), but wondering, hoping, you have a course that focuses on the current OWASP Top 10?

  2. How do I build a method on SqlDataAccess to do a select by EmployeeId. I found all kind of examples online but none that matches the way you do it with generics. I tried this with no luck "var job = cnn.QueryFirstOrDefault<JobStopDataModel>(sql, new { jobNumber = 25900 });"

  3. Hello! I'm getting an error that was posted before, to be exact : System.NullReferenceException: 'Object reference not set to an instance of an object.'

    System.Configuration.ConnectionStringSettingsCollection.this[string].get returned null.
    This appears on the SQLDataAccess page under the first function for GetConnectionString and primarily involved the value MVCDB. I did create the connection string using MVCDB in my web.config file and named my database MVCDB (not adding demo). I was wondering if you have any advice on a fix.

  4. I'm getting the following exception:

    Message=Incorrect syntax near the keyword 'Employee'.

    Source=.Net SqlClient Data Provider

    I have both Dapper and EntityFramework on my MVC app, could this be the problem or is it just SQL related?

  5. sorry if this is a dumb question Tim, but after seeing in this video how you separate the business logic from the MVC part of the app, which makes a lot of sense, I became curious and did a little bit of reading on multi layer architecture. So my question is, is there any particular reason why you didn't put the business logic and database access in their own separate layers for better decoupling, instead of having them both live in the same library? Maybe it wasn't worth it for the purpose of this tutorial? Would you still do it this way in a different context like in a real enterprise application? Or maybe they could still be considered separate layers even though they're in the same library? Trying to better understand which would be the better approach or the one more likely to show up in a real world environment. Thanks a lot for sharing your knowledge with us!

  6. Tim your channel is an absolute goldmine of programming knowledge. It amazes me how well you relate all your coding to the higher level programming concepts you aim to explain. I have used your MVC videos to introduce myself to the field of web development. Because of you I am confident in creating a simple website using MVC and am now looking to expand my horizons. However I have encountered an problem. There seems to be so many directions to go from here, and I'm struggling to figure out which are most relevant and useful to me. My question to you is, for someone interesting in web development, who has a solid understanding of OO principles, SQL and front end design langauges (css, javascript, html) yet has only started to combine them using platforms like MVC, what are the next steps to take?

  7. Hello Tim 🙂 i got an error which makes me crazy :

    System.Data.SqlClient.SqlException: "An explicit identity column value cannot be inserted in the Emergency Services_Db table if IDENTITY_INSERT is set to OFF."
    Please help me.

  8. Tim, I followed several of your videos as I started learning ASP.NET with MVC. They've been a great help to me in forming the basis of a project idea I'm working on. I've learnt a lot from the videos and been able to expand my knowledge from your tutorials: they've been a great help. Thank You. I've recently started deploying the app to IIS for testing, using SQL Express as the database. There were a few teething problems related to permissions, which I was able to resolve. One point I have difficulty with is creation of the data tables in the SQLExpress database. I'm using Identity framework (from another of your videos) and found that the identity database tables are created automatically. However I find the application tables (dbo.Table etc) are not created. I googled extensively and can only find recommendations to use EF. I don't want to migrate / refactor, so can you suggest how I can get the .sql files to run to create the application data tables? I have 30+ tables, so don't want to recreate a script for each. The Dapper docs weren't much help, I found.

  9. I get this exception when i try to view my data in my tble

    System.Data.SqlClient.SqlException: 'Cannot insert the value NULL into column 'Id', table 'MRIProjectDB.dbo.SignUp'; column does not allow nulls. INSERT fails.

    The statement has been terminated.'

  10. I really like the approach you took but I do have a question. I do like how you made it where the sql request come from another project so that way multiple applications may use it. My main question is though which you may or may not have a answer to, is there a solution out there sort of like eloquent in Laravel where we can query our database from the model directly using eloquents helpers. I ask this question because so far I really love ASP.NET MVC and may fully convert over but I feel that this could be more simplified with a tool like eloquent so that way we may even configure the MVC to use multiple kinds of databases without much effort?… This may sound lazy in some way but I would really like to see a tool like that where we can configure relationships and what not.

  11. I get this exception when I try to install dapper:
    Exception 'System.AggregateException' thrown when trying to add source 'http://packagesource'. Please verify all your online package sources are available.

    One or more errors occurred.

    Unable to load the service index for source http://packagesource.

    An error occurred while sending the request.

    The remote name could not be resolved: 'packagesource'

  12. At 1:03:22 I'm getting an Exception User-Unhandled System.NullReferenceException: 'Object reference not set to an instance of an object.'

    System.Configuration.ConnectionStringSettingsCollection.this[string].get returned null.

    Please help ):

  13. thanks for explaining how type T works at 49:00–50:00 where as other people would gloss over it. You have a keen eye for frequently misunderstood aspects of C# and it's smart of you to explain those things in detail.

  14. At 46:45, the option you chose does not appear to me, what could it be?
    "ConfigurationManager" Not working because of that.

  15. 47:00 and onwards I understood absolutely nothing. Are there any previous videos where you explain what does ConfigurationManager.ConnectionStrings actually do?

  16. Need help, after installing Dapper, it doesn't pick it up when trying to add it "using Dapper". When I put it's just seen as an error


Please enter your comment!
Please enter your name here