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

Databases

Pratham Patel
Pratham Patel
565 Points

Can someone explain how C# uses databases and what SQL is used for? How does one store data into a database in C#?

How do I connect to a database in C# and what are the the options available. Thanks

1 Answer

Steven Parker
Steven Parker
231,261 Points

SQL is the language of databases. Instructions written in SQL for the database are called "queries". One option in C# is to use library calls to establish a database connection and pass queries directly to the database.

But a much more elegant option is to use "Entity Framework". This maps database tables into model objects and makes it easy to read and update the database. There are several Treehouse courses that teach Entity Framework programming.

Pratham Patel
Pratham Patel
565 Points

Would you suggest I learn sql and entity if I'm going to develop in c#

Steven Parker
Steven Parker
231,261 Points

It's good to know SQL no matter what language you normally program in, so you can interact directly with the database when needed.

But you won't need SQL when you develop with Entity Framework. It lets you handle your database through C# objects and it takes care of the SQL behind the scenes for you. EF is definitely the way to go for database access in C#.