Hi Ainguahj,
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of NorthWind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="Customer Id" />
<asp:BoundField DataField="ContactName" HeaderText="Contact Name" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
Namespaces
C#
using NorthwindModel;
VB.Net
Imports NorthwindModel
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
var id = "AAFKM";
NorthwindEntities entities = new NorthwindEntities();
var result = (from c in entities.Customers
where c.CustomerID == id
select c).ToList();
gvCustomers.DataSource = result;
gvCustomers.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim id = "AAFKM"
Dim entities As NorthwindEntities = New NorthwindEntities()
Dim result = (From c In entities.Customers Where c.CustomerID = id Select c).ToList()
gvCustomers.DataSource = result
gvCustomers.DataBind()
End Sub
Screenshot
