Display Data From DataBase With LINQ To SQL
First Start Visual Studio, Then Select File -> New -> Project
Then a dialog box appear, Choose the Console Application
After that give the name of application as i did "test" my application name.
Then goto the "Project" Option and select "Add New Item" a dialog box appear
the select the "LINQ To SQL Classes"
Give the name of that File, by default is "DataClasses1.dbml"
Go to the Server Explorer and Drag the table name from the database and
drop it on the "DataClasses1.dbml" file.
The Write The Following Program...
To Program.cs file
//I used "test" as a namespace because my application name is "test"
using System;
using System.Linq;
using test;
class LINQToSQL
{
static void Main()
{
DataClasses1DataContext dc =
new DataClasses1DataContext();
var result = from c in dc.Categories select c;
foreach (var r in result)
Console.WriteLine("Category Id is " + r.CategoryID +
" Category Name is " + r.CategoryName);
Console.ReadLine();
}
}
OUTPUT
Display Data From DataBase With LINQ To SQL
Reviewed by Baljeet Singh
on
14:30
Rating:
No comments: