ASP.NET database connection and queries
Someone asked on Stack Overflow:
I’m used to PHP style MVC frameworks which are a little different from the way ASP’s MVC frameworks work.
Is there a built in database class? Or do I need to code my own database class using a web.conf connection string?
With PHP’s MVC frameworks you simply add your database connection information into a database and then query it with something like:
$results = $this->db->query("select * from table");
I posted the following answer, which was chosen as the accepted answer and received 2 upvotes:
It is not quite that simple, but you have a lot more flexibility. Check this link out: http://www.dotnetperls.com/sqlconnection — It has some getting started for doing exactly what you’ve outlined (though I HIGHLY recommend you use sprocs or at a minimum, paramaterized sql, not direct sql).
With that said, I suggest you look into Linq-To-SQL or Entity Framework. Any on-line sampels you find will probably use one of these technologies, and they do make things very nice and simple.
Originally posted on Stack Overflow — 2 upvotes (accepted answer). Licensed under CC BY-SA.