Showing posts with label Linq. Show all posts
Showing posts with label Linq. Show all posts

Monday, March 25, 2013

How to insert the multiple values using LINQ in asp.net


In previous posts we have seen  how to insert the data into data base using sql server in asp.net with c sharp.  Now  i will given an example to insert the multiple fields  using LINQ in asp.net.Here i have used USING  to maintain the scope of the patientinfo.
using (PatientInfo pf = new PatientInfo())
{
t_patientDetails objpd =new t_patientDetails()
objpd.Name = Name;
objpd.Mobile = Mobile;
objpd.OPNO = OPNO;
objpd.Date = DateTime.Now;
pf.t_patientDetails.InsertOnSubmit(objpd);
pf.SubmitChanges();
}

Thursday, October 25, 2012

Bind data to gridview using LINQ in asp.net

In previous posts we have seen how to bind the data to gridview and bind data to dropdown in gridview in asp.net.In this post i will given how to bind and filter the data then bind to grid view using LINQ in Asp.net.Here i have placed a button and grid view then get the orders data with linq query.
//add name spaces
System.Data.SqlClient;
System.Linq; 
//button click_event
SqlConnection con=new SqlConnection("User id=sa;password=;Databse=test;server=localhost");
SqlDataAdapet ad=new SqlDataAdapater("Select * from products",con);
Dataset dslq=new Dataset();
da.Fill(ds,"d");
DataTable dtlq=dslq.Tables("d");
Enumerable <DataRow> Edr=dtlq.AsEnumerable();
Queryable <DataRow> EQ=dtlq.AsQueryable();
EQ=From i in EQ where i["ordername"].Tostring=="Computer" select i;
EQ=From i in EQ where int.parse(i["orderid"].Tostring())<5 select i;
GvOrder.DataSourcec=QE.CopyToDataTable();





Monday, July 2, 2012

Complete details about linq in sharepoint

what is LINQ?
LINQ Stands for Language Integrated Query , which  is used by the .net developers to query and transform the data .LINQ is a new data access paradigm,which allows the users to use SQL like Syntax in various data sources through out the application .
What is the main uses of LINQ?
By Allowing  the backend data resources to decide which way is the best to resolve the query , LINQ can improve the performace of the application .Now with sharepoint supporting the LINQ ,its makes query information for the platform easy through LINQ Query Listing in a condensed and easy format .
what are the fetaures of linq in sharepoint?
1) LINQ processes its queries through Custom Query provider that translaters LINQ quries through CAML ,which is a Collaborative Application Markup language which is later on used by the Sharepoint.
2)LINQ also extends its support in C# 3.0 and Visual Basic 9.0 .Visual Studio Integration for the Entity Creation is also known as SPML .
3)Entity Creation tool SpMetal to export SharePoint List definations to entity Classes used for querying .
4) LINQ can be connected to Sharepoint via ,Sharepoint Object model or through Sharepoint Web Services .
5) LINQ also provides the extended support to update through the entity Type.

Thursday, January 5, 2012

OrderBy and GroupBy in LINQ

If you are familiar with SQL,You would know it can enable you to perform some relational operations like the data to be returned in a specific Order and get the summary values based on the rows in each group.Here the LINQ is provide the same functionality
OrderBy:
The OrderBy is used to retrieve the data in particular order.The OrderBY expects a method as its argument.This methods identifies expressions that you want to use to sort the data.
For this i will show an example to get names of each city in AllCountry array
IEnumerable citynames=Allcountry.OrderBy(acoun=>acoun.CityName).Select(City=>city.CityName)
List li=New List();
 foreach(string name in Country)
  {
         li.add(name);
  }
 foreach (string s in list) // Loop through List with foreach
  {
 Console.WriteLine(s);
  }
The OrderByDescending is get the data in descending order.Here there one method i.e ThenByDescending which is used for more than one key value
GroupBy:
The GroupBy method is used to group the data to common values in one or more Fields.The GroupBy method expects a methods that specify the fields to group the data
var citiesGroupByCountry= Allcountry.GroupBy(acoun=>acoun.Country);
foreach(var citiesPerCountry in citiesGroupByCountry)
{
 foreach(var citis in citiesPerCountry)
 {
   Console.Writeline(Country.CountyName);
 }
}

Bel