Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# ASP.NET MVC Basics Views Setting Data in the Controller

Jake Ford
Jake Ford
9,230 Points

Pulling data from MySQL database via the Controller?

So would it be possible to connect to a MySQL database and pull content from there rather than adding static content to the Controller? I have used PHP and MySQL before, but never with .NET. Any good information on doing something like this?

Something like:

var title = "SELECT title FROM artists";

Then pass it to the view?

1 Answer

James Churchill
James Churchill
Treehouse Teacher


Absolutely, yes! I'm not introducing querying data from a database in the course in order to keep the focus on learning MVC. In the .NET world, developers often use Entity Framework to work with databases, but you could use ADO.NET as well.

If you want to learn about Entity Framework, check out our course that'll teach you the basics:


Then take a look at this course which will show you how to use EF with MVC:


We use SQL Server LocalDB for our databases in those courses. If you want to connect to a MySQL database, check out this provider for EF:


I hope this helps!

Thanks ~James

Jake Ford
Jake Ford
9,230 Points

Thank you, I'll check out these courses for sure.