LINQ Select Query with
where:
Below LINQ query will
get the Students details from table with where condition
var students = from stu in sqlObj.tbl_students
where
stu.Id==100
select
new
{
stu.Id,
stu.Name,
};
Asp.net Code
<form
id="form1" runat="server">
<div>
<center>
<asp:GridView ID="gv1" runat="server"></asp:GridView>
</center>
</div>
</form>
<div>
<center>
<asp:GridView ID="gv1" runat="server"></asp:GridView>
</center>
</div>
</form>
C#.net Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Select_With_where
: System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
MydbDataContext sqlObj = new
MydbDataContext();
var students = from
stu in sqlObj.tbl_students
where
stu.Id==100
select
new
{
stu.Id,
stu.Name,
};
gv1.DataSource = students;
gv1.DataBind();
}
}
OutPut
No comments:
Post a Comment