Introduction:
In this article,we are going to discuss how to use linQ against Dataset.
Main:
Linq-to-SQL is an Object/relational (O/R) mapping implementation that allows developers and architectures to model a relation database using .NET classes.
Operations on classes are translated to commands for Crate/Read/Update/Delete (CRUD) statements that modify the underlying database through a regular connection.
Please see the below examble,
Linq to dataset.aspx.cs,We are just filtering data’s in DataTable.
using System; using System.Data; using System.Data.SqlClient; using System.Collections; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Xml.Linq; public partial class NetProgrammingHelp : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string connString = @"server=Databse1;Integrated security=true;database=master"; string cmd = "SELECT * FROM dept;SELECT * FROM emp"; SqlDataAdapter adapter = new SqlDataAdapter(cmd, connString); DataSet ds = new DataSet(); adapter.Fill(ds); var dept = ds.Tables[0].AsEnumerable(); var emp = ds.Tables[1].AsEnumerable(); var data = from d in dept join m in emp on d.Field<int>("deptno") equals m.Field<int>("deptno") select new { empno=m.Field<int>("empno"),ename=m.Field <string>("ename"), dname=d.Field <string>("dname")}; //var res = from d in dept // select new { dno=d.Field<int>("deptno"),dn=d.Field<string>("dname"),loc=d.Field<string>("loc")); GridView1.DataSource = data; GridView1.DataBind(); } } |
Conclusion:
Hope this helps,
Happy Coding.
Genial brief and this mail helped me alot in my college assignement. Thanks you for your information.
Brim over I to but I contemplate the brief should prepare more info then it has.
Hi
Very nice and intrestingss story.