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
STAFF
James Churchill
Treehouse Teacher

Jacob,

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:

https://teamtreehouse.com/library/entity-framework-basics

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

https://teamtreehouse.com/library/entity-framework-with-aspnet-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:

https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html

I hope this helps!

Thanks ~James

Jake Ford
Jake Ford
9,230 Points

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