Hi yogesjoshi,
Refer the below sample.
SQL
SELECT EmpId,Name,Designation,GroupName FROM Employee
Output
EmpId |
Name |
Designation |
GroupName |
1 |
John Tom |
Accountant |
Accounts |
2 |
P K Johns |
Technician |
Technical |
3 |
Kevin Ob |
Adminstrator |
Admin |
4 |
Rose Marry |
Accountant |
Accounts |
C#
int empid = 1;
string empname = "John Tom";
TestEntities context = new TestEntities();
var Emplist = context.Employees.FirstOrDefault(x => x.EmpId == empid && x.Name == empname);
List<Employee> list = new List<Employee>();
if (Emplist != null)
{
list = new List<Employee>
{
new Employee
{
EmpId=Emplist.EmpId,
Name = Emplist.Name,
Designation=Emplist.Designation,
GroupName=Emplist.GroupName
}
};
}
gvEmployees.DataSource = list;
gvEmployees.DataBind();
VB.Net
Dim empid As Integer = 1
Dim empname As String = "John Tom"
Dim context As New TestEntities()
Dim Emplist = context.Employees.FirstOrDefault(Function(x) x.EmpId = empid AndAlso x.Name = empname)
Dim list As New List(Of Employee)()
If Emplist IsNot Nothing Then
list = New List(Of Employee)() From {
New Employee() With {
.EmpId = Emplist.EmpId,
.Name = Emplist.Name,
.Designation = Emplist.Designation,
.GroupName = Emplist.GroupName
}
}
End If
gvEmployees.DataSource = list
gvEmployees.DataBind()
Output
EmpId | Name | Designation | GroupName |
1 |
John Tom |
Accountant |
Accounts |