Prabu Spark

Prabu Spark

  • NA
  • 124
  • 204.5k

what is the use of relations in dataset c#

Jul 1 2013 5:01 AM
Hi sir,
 Tell me the use of relations in dataset c# . I made relation using two datatables, for a dataset.
My problem is what is the use of datarelations in datasets. Kindly give me the solution with proper
examples.


 protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["con"].ConnectionString);
        SqlCommand cmd;
        con.Open();
        string query = "select * from emp";
        DataSet ds = new DataSet();
        cmd = new SqlCommand(query, con);
        SqlDataAdapter sda = new SqlDataAdapter();
        sda.SelectCommand = cmd;
        sda.Fill(ds, "emp");

        cmd.Dispose();

        string query1 = "select * from empl";
        cmd = new SqlCommand(query1, con);

        sda.SelectCommand = cmd;
        sda.Fill(ds, "empl");
        ds.Relations.Add("employees_list", ds.Tables["emp"].Columns["eid"], ds.Tables["empl"].Columns["eid"],false);

        GridView1.DataSource = ds;
        GridView1.DataBind();
            

        con.Close();


    }

Answers (3)