Accepted answer

theres a very simple way to connect to a database although i suggest you read the app config afterwards and other parts of your project to see how it works.

in the menu strip go to data -> add new data source. from here pick database then entity data model. follow the rest of the steps to create a datasource for your project.

in your program you can create an object of the datasource by using:

whatyoucalledthedatasource datasourceobject = new whatyoucalledthedatasource();

you can then make queries on this object by changing your first line of the query to:

var adultnames = from person in datasourceobject.people 

to get the data you want, once you have the query you can place the results into a list like:

list<string> queryresults = new list<string>();


bearing in mind that i basing on the thought that name would be a string. you can also create lists based on tables like

var adultnames = from person ...
                 select person;
list<people> queryresults = new list<people>();


if you have a look at this nerddinner pdf file that creates a mvc solution, it shows step by step how to create a dataset using linq to sql


it sounds like you have been looking at examples of linq, which allows you to query from a data set. what you need in addition is called an object relational mapper (orm). look at linq to sql or the entity framework (newer) to get starts with this. this layer will introspect a database and create a lot of infrastructure to pull data out for you based on the data model.


there are a number of ways to retrieve data from a database. is the general technology. your specific options are:

you can use the standard query system in to get data from any database that uses odbc, or use native data providers such as sqlclient or odp. the sqlclient namespace may be used to get data from sql server. the oracle data provider (odp) is used with oracle.

you have to write the queries/stored procedures yourself using "raw"

here is an excellent listing of example code:

here is a link to oracle's odp:

linq to sql

linq to sql is a linq provider specifically for the sql server database. it is still supported, but is superseded by entity framework.

more detail here:

entity framework

entity framework works natively with sql server and can work with oracle using third-party or open-source data providers.

entity framework 4/4.1 will allow you to use an entity data model (edm) as an abstraction of your database. the edm will surface a set of objects with which you can interact, and a context object is used to retrieve/commit data to the database. the crud queries are dynamically generated from your linq syntax, so you don't have to write t-sql or pl-sql queries yourself in most cases.

here is a basic example of entity framework:


if you have a database table people then you can use linq-to-sql to return information from it, first you need to reference the following two assemblies.


define the following entity like this:

class people
    public int age { get; set; };
    public string name { get; set; };

then you can write tour query against database

datacontext db = new datacontext("database connection string");
var adultnames = from person in db.gettable<people>()
             where person.age >= 18

Related Query

More Query from same tag