Linq to SQL Connection in asp.net Csharp

29. June 2010

In this Example, I have Create a connecton string and establish a connection between object to database. and Select title from employees table.

string connectionString = "Data Source=.;Initial Catalog=Northwind;Integrated Security=True";
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            using (NorthwindDataContext context = new NorthwindDataContext(connection))
            {
                var query = from c in context.employees
                            select c.Title;

                foreach (var title in query)
                {
                    Response.Write(title);
                }
            }


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, asp.net 4.0 ,


Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading





User Name: Guest

Your Ip: 38.107.191.91
Time: