Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;


public partial class _Default : System.Web.UI.Page 
{
    OleDbConnection cn;
    DataSet ds;
    OleDbDataAdapter oda1,oda2;
    DataTable dt1,dt2,dt3;
    DataRow dr;
    DataColumn c1, c2, c3,c4,c5,c6;

    protected void Page_Load(object sender, EventArgs e)
    {
        cn = new OleDbConnection("provider = Microsoft.Jet.OLEDB.4.0; data source = c:\\db1.mdb");
        cn.Open();
        ds = new DataSet();
        oda1 = new OleDbDataAdapter("select * from emp", cn);
        oda1.Fill(ds, "emp");
        oda2 = new OleDbDataAdapter("select * from dept", cn);
        oda2.Fill(ds, "dept");


    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        GridView1.DataSource = ds.Tables[0].DefaultView;
        GridView2.DataSource = ds.Tables[1].DefaultView;
        GridView1.DataBind();
        GridView2.DataBind();
        GridView1.Visible = true;
        GridView2.Visible = true;

    }
    protected void Button2_Click(object sender, EventArgs e)
    {

        dt1 = new DataTable();
        dt1.TableName = "T1";

        dt2 = new DataTable("T2");
        dt3 = new DataTable("T3");

 
        c1 = new DataColumn("eName");
        c2 = new DataColumn("eId");
        c3 = new DataColumn("Did");
        c4 = new DataColumn("Did");
        c5 = new DataColumn("dName");
        c6 = new DataColumn("dAddress");

        dt1.Columns.Add(c1); dt1.Columns.Add(c2);
        dt1.Columns.Add(c3);

        dt2.Columns.Add(c4);
        dt2.Columns.Add(c5);
        dt2.Columns.Add(c6);

        for (int i = 0; i < 5; i++)
        {
            dr = dt1.NewRow();

            dr[0] = "a" + i;
            dr[1] = "b" + i;
            dr[2] = "c" + i;
            
            dt1.Rows.Add(dr);
            
        }

        ds.Tables.Add(dt1);
        


        for (int i = 0; i < 5; i++)
        {
            dr = dt2.NewRow();

            dr[0] = "c" + i;
            dr[1] = "x" + i;
            dr[2] = "y" + i;

            dt2.Rows.Add(dr);

        }

        ds.Tables.Add(dt2);

        GridView1.DataSource = ds.Tables["T1"].DefaultView;
        GridView1.DataBind();
        GridView2.DataSource = ds.Tables["T2"].DefaultView;
        GridView2.DataBind();
        GridView1.Visible = true;
        GridView2.Visible = true;

        dt1.Merge(dt2, false, MissingSchemaAction.AddWithKey);

        GridView3.DataSource = dt1;
        GridView3.DataBind();
        GridView3.Visible = true;

    }
    protected void Button2_Click1(object sender, EventArgs e)
    {
        
    }
}


i need out put of this programe as shown in image below
See here for image or http://www.freeimagehosting.net/uploads/a93c18e8eb.jpg

When iam creating 2 dynamic tables with 1 common column loaded with dynamic data in it and when iam merging this 2 tables
the out put is like the image in the link
please do help me solving this problem

thanks a million in advance
Posted
Comments
Sandeep Mewara 14-Jul-10 13:49pm    
What have you tried? What is the issue?

iam trying to make 2 dynamic tables and want to merge them using common column "did" but out put is not clear

  emp                                       dept
eno ename did                       did dname daddress
1    sa    10                        10  IT    Hyd
2    sam   20                        20  Phy   Hyd
3    ram   30                        30  Bio   Hyd

now i need out put as 

                         comb
             eno ename did dname daddress
             1    sa    10  IT    Hyd
             2    sam   20  Phy   Hyd
             3    ram   30  Bio   Hyd

but out put is coming like this 

                       comb
             eno ename did dname daddress
             1    sa    10   
             2    sam   20   
             3    ram   30   
                        10  IT    Hyd
                        20  Phy   Hyd
                        30  Bio   Hyd



and the code is mentioned above 
is there any coding or solution to get the desired output 
 
Share this answer
 
any help please any one there to help me /............
 
Share this answer
 
Comments
Khaniya 16-Aug-10 7:41am    
why are you adding comments as answer ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900