Vipin Kumar
how we can bind data in single gridview from two tables...plz this is urgent for me... someone help me..... thanks in advance...
By Vipin Kumar in ADO.NET on Sep 03 2010
  • vinay singh
    Mar, 2016 30

    g

    • 0
  • Ruchi R
    Sep, 2010 8

    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.

    • 0
  • Satyapriya Nayak
    Sep, 2010 7

    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();
        }
    }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS