what is the use of relations in dataset c#

Posted by Prabu_Spark under ASP.NET on 7/1/2013 | Points: 10 | Views : 1115 | Status : [Member] | Replies : 1
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();


}

With regards,
J.Prabu.
[Email:prbspark@gmail.com]



Responses

Posted by: Satyapriyanayak on: 7/1/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
In a DataSet with multiple DataTable objects, you can use DataRelation objects to relate one table to another, to navigate through the tables, and to return child or parent rows from a related table.


http://msdn.microsoft.com/en-us/library/ay82azad.aspx
http://www.c-sharpcorner.com/UploadFile/c59e94/defining-datarelation-in-a-dataset/

If this post helps you mark it as answer
Thanks

Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response