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 trialPratham Patel
565 PointsCan 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
231,261 PointsSQL 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
565 PointsPratham Patel
565 PointsWould you suggest I learn sql and entity if I'm going to develop in c#
Steven Parker
231,261 PointsSteven Parker
231,261 PointsIt'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#.