3
Reply

how we can bind data in single gridview from two tables...plz this is urgent for me... someone help me..... thanks in advance...

Vipin Kumar

Vipin Kumar

Sep 03, 2010
13.9k
0

    g

    vinay singh
    March 30, 2016
    0

    hi,

    you can use inner join to select datas of two table in query and then bind the data in a gridview.

    I hope this will help you.

    Ruchi R
    September 08, 2010
    0

    Hi Vipin,

    Here is you code


    using System;
    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;
    public partial class _Default : System.Web.UI.Page
    {
        string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlDataAdapter ad ;
        DataSet ds1 = new DataSet();
        DataSet ds2 = new DataSet();
        string str1;
        string str2;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindgrid();
            }
        }
        private void bindgrid()
        {
            SqlConnection con = new SqlConnection(connStr);
            con.Open();
            str1="Select * from employee";
            str2 = "Select * from product";
            ad = new SqlDataAdapter(str1, con);
            ad.Fill(ds1, "MyTable");
            ad = new SqlDataAdapter(str2, con);
            ad.Fill(ds2, "MyTable");
            ds1.Merge(ds2);
            //ResultGridView.DataSource = ds1.Tables[0].DefaultView;
            ResultGridView.DataSource = ds1;
            ResultGridView.DataBind();
        }
    }

    Satyapriya Nayak
    September 07, 2010
    0