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();
}
Loading
Jignesh TrivediPosted Jul 1, 2013, 11:24 PM
A DataRelation is used to relate two DataTable objects to each other through DataColumn objects.Relationships are created between matching columns in the parent and child tables. That is, the DataType value for both columns must be identical.
Please refer for more details
http://www.codeproject.com/Articles/18304/Using-Data-Relation-with-Data-Table
http://msdn.microsoft.com/en-us/library/system.data.dataset.relations.aspx
hope this will help you.
Kunal VaishyaPosted Jul 1, 2013, 9:12 AM
This is mostly use for data representation in linking way if you have a Telerik or Devexpress Grid then Hust Bibd you will see the data automatically display in Hierarchical table or record.
Posted Jul 1, 2013, 5:10 AM
You can enforce Cascading delete/update, foreign key references.... the same how it is present in the database.
http://blogs.msdn.com/b/spike/archive/2010/02/18/parent-child-datarelation-the-basics.aspx