score:3
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>();
queryresults.addrange(adultnames);
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>();
queryresults.addrange(adultnames);
score:1
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
score:2
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.
score:2
if you're using linq to sql, then this may help: http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx
entity framework: http://www.codeguru.com/csharp/csharp/net30/article.php/c15489
score:2
there are a number of ways to retrieve data from a database. ado.net is the general technology. your specific options are:
system.data/sqlclient/odp
you can use the standard query system in ado.net 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" ado.net.
here is an excellent listing of ado.net example code: http://msdn.microsoft.com/en-us/library/dw70f090.aspx
here is a link to oracle's odp:
http://www.oracle.com/technetwork/topics/dotnet/index-085163.html
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: http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx
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:
http://www.codeproject.com/kb/database/sample_entity_framework.aspx
score:2
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.
using system.data.linq;
using system.data.linq.mapping;
define the following entity like this:
[table]
class people
{
[column]
public int age { get; set; };
[column]
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
select person.name;
Source: stackoverflow.com
Related Query
- C# LINQ How to get a data source from a db?
- C# LINQ or for loop How to get a data source from a db?
- How does linq actually execute the code to retrieve data from the data source?
- How to get children data from json via linq
- How can I get data from my database in LINQ C#?
- How to get linq to transform data from one form to another
- LINQ - How to get data from multiple tables
- How to write linq to get data from different tables?
- How to Get data in repeater from multiple table using like linq query
- How to reinsert data from one table onto itself using LINQ in code migration?
- How to get data from linq query using select
- How to get a column value from data table with Linq
- How to get data from a Table if they exist in another Table C# LINQ
- How to convert data from two tables get from Linq query to List witch can be populated in wpf form
- How I get the right Data from my Column with Linq
- c# Linq or code to extract groups from a single list of source data
- how to fetch data from database using linq query for relationship 1:N and N:N (between 3 entity) in asp.net mvc EF code first?
- How to use LINQ to get data from an XML file?
- How to get data using select from a nested properties - linq
- How to group and subgroup and get data from a linq query
- how to get data from linq database model
- How to get rows of Data from Multiple Tables using LinQ To Entities
- Linq to Sql - How to get data from second level table
- How to get first object out from List<Object> using Linq
- How to get distinct instance from a list by Lambda or LINQ
- How to get the TSQL Query from LINQ DataContext.SubmitChanges()
- How to get linq `ForEach` statement to return data on the method call being made for each list object?
- How to get the latest date inserted from the table with Linq to entities
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- How to get Distinct Values from List(Of T) using Linq
More Query from same tag
- linq .Value Nullable Object must have a value. How to skip?
- How to compare Date in LINQ(Likewise Like in SQL query)
- Getting the Rows from DataTable1 where they are not in DataTable2
- Better way to combine two objects with linq?
- Purpose of EF 6.x DbContext Generator option when adding a new data item in Visual Studio
- LINQ get the best match from the list comparing strings
- Linq query for latest status in asp.net
- Using Dictionary<T1, T2> in LinQ query
- How to get files from a specific sub-directories using c#?
- How to filter datatable rows in debug mode
- Linq filter by time range
- Linq optional parameters
- Checking for solo nodes in LINQ to XML
- get commmon properties of two different object using c#
- How to check for key-value pair mapping in this scenario?
- How to search data from Database using Linq
- querying list within a list using linq
- "Subquery returned more than 1 value. This is not permitted." Need to return a set of values
- How to use LINQ to filter property of child collection using (.Any())
- Left Join Linq Group by on Child table
- How to implement First and FirstOrDefault for boolinq?
- How to get a Random Object using Linq
- DataGridView Loading From LINQ
- Dotnet EF Core Linq string contains in a list string split by comma
- ListBox grouping and LINQ
- How to use LINQ to sort custom items by using StartWith
- search value in excel using Linq
- Linq to FileHelpers Class
- Get values by property name from an object at different levels
- Code First EF 6 Table Per Hierarchy SQL query generation issue