Hi nauna,
Refer below sample.
If you use union the you will get distict record from both tables. And if use concat then you will get all record from both table means duplicate data.
HTML
<asp:GridView ID="gvConcat" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
<br />
<asp:GridView ID="gvUnion" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
Namespaces
C#
using TestModel;
VB.Net
Imports TestModel
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
TestEntities entity = new TestEntities();
var result1 = (from customer in entity.Customers
select new
{
CustomerId = customer.CustomerId,
Name = customer.Name,
Country = customer.Country
});
var result2 = (from customerTest in entity.CustomerTests
select new
{
CustomerId = customerTest.CustomerId,
Name = customerTest.Name,
Country = customerTest.Country
});
var concat = result1.Concat(result2);
gvConcat.DataSource = concat;
gvConcat.DataBind();
var union = result1.Union(result2);
gvUnion.DataSource = union;
gvUnion.DataBind();
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim entity As TestEntities = New TestEntities()
Dim result1 = (From customer In entity.Customers Select New With {Key .CustomerId = customer.CustomerId, Key .Name = customer.Name, Key .Country = customer.Country})
Dim result2 = (From customerTest In entity.CustomerTests Select New With {Key .CustomerId = customerTest.CustomerId, Key .Name = customerTest.Name, Key .Country = customerTest.Country})
Dim concat = result1.Concat(result2)
gvConcat.DataSource = concat
gvConcat.DataBind()
Dim union = result1.Union(result2)
gvUnion.DataSource = union
gvUnion.DataBind()
End If
End Sub
Screenshot