2
Answers

Bind two multiple columns into single datatable

murali athmuri

murali athmuri

12y
1.9k
1
Sir,

I have two datatables dk,dc
How to combine two datatable into single datatable.
I am using merge function but data will add like tree way. i don't want to that way.I want store data in side by side column and bind to gridview. Can u Please solve my problem



Answers (2)
0
murali athmuri

murali athmuri

NA 40 44.6k 12y
output will be displayed in tree formate.I don't want like that way, i want side by side in grid
0
Satyapriya Nayak

Satyapriya Nayak

NA 53k 8m 12y
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Merge
{
    public partial class _Default : System.Web.UI.Page
    {
        string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlDataAdapter sqlda1, sqlda2;
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindgrid();
            }
           
        }
        public void bindgrid()
        {
            SqlConnection con = new SqlConnection(strConnString);
            con.Open();
            sqlda1 = new SqlDataAdapter("select * from table1", con);
            sqlda2 = new SqlDataAdapter("select * from table2", con);
            DataSet ds1 = new DataSet();
            DataSet ds2 = new DataSet();
            sqlda1.Fill(ds1, "table1");
            sqlda2.Fill(ds2, "table1");
            ds1.Merge(ds2, false, MissingSchemaAction.Add);
            GridView1.DataSource = ds1;
            GridView1.DataBind();

        }
    }
}