Hi ramco1917,
Please refer below sample.
SQL
CREATE TABLE [PurchaseTable]
(
[ItemCode] INT PRIMARY KEY,
[QtyRecd] INT,
)
INSERT INTO [PurchaseTable] VALUES (1,10)
INSERT INTO [PurchaseTable] VALUES (2,4)
CREATE TABLE [IssueTable]
(
[ItemCode] INT PRIMARY KEY,
[QtyIssued] INT
)
INSERT INTO [IssueTable] VALUES (1,2)
INSERT INTO [IssueTable] VALUES (2,0)
SELECT * FROM [PurchaseTable]
SELECT * FROM [IssueTable]
HTML
<asp:GridView runat="server" ID="gvDetails"></asp:GridView>
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
subSum();
}
}
public void subSum()
{
AjaxSamplesEntities entities = new AjaxSamplesEntities();
var result = from pt in entities.PurchaseTables
join it in entities.IssueTables on pt.ItemCode equals it.ItemCode
select new
{
ItemCode = pt.ItemCode,
QtyRecd = pt.QtyRecd,
QtyIssued = it.QtyIssued,
QtyBalance = pt.QtyRecd - it.QtyIssued
};
gvDetails.DataSource = result.ToList();
gvDetails.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
subSum()
End If
End Sub
Public Sub subSum()
Dim entities As AjaxSamplesEntities = New AjaxSamplesEntities()
Dim result = From pt In entities.PurchaseTables
Join it In entities.IssueTables On pt.ItemCode Equals it.ItemCode
Select New With {Key _
.ItemCode = pt.ItemCode,
.QtyRecd = pt.QtyRecd,
.QtyIssued = it.QtyIssued,
.QtyBalance = pt.QtyRecd - it.QtyIssued
}
gvDetails.DataSource = result.ToList()
gvDetails.DataBind()
End Sub
Screenshot