<asp:panel id="Panel1" runat="server" groupingtext="Dept table" xmlns:asp="#unknown">
<asp:dropdownlist id="DropDownList1" runat="server">
|
<asp:panel id="Panel2" runat="server" groupingtext="Doctor table" xmlns:asp="#unknown">
<asp:gridview id="GridView1" runat="server">
|
<asp:panel id="Panel3" runat="server" groupingtext="Patient table" xmlns:asp="#unknown">
<asp:gridview id="GridView2" runat="server">
|
using System.Data.SqlClient;
namespace onetoonerelationapp
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string cs = "server=NAIDU-173927C10;database=hospital;uid=sa;pwd=nanda";
SqlConnection conn = new SqlConnection(cs);
conn.Open();
SqlCommand cmd1 = new SqlCommand("select * from dept", conn);
SqlCommand cmd2 = new SqlCommand("select * from doctor", conn);
SqlCommand cmd3 = new SqlCommand("select * from patient", conn);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
SqlDataAdapter da3 = new SqlDataAdapter(cmd3);
DataSet ds = new DataSet();
da1.Fill(ds, "deptnew");
da2.Fill(ds, "doctornew");
da3.Fill(ds, "patientnew");
ds.Relations.Add("deptdoct", ds.Tables["deptnew"].Columns["deptid"], ds.Tables["doctornew"].Columns["deptid"]);
ds.Relations.Add("deptpatient", ds.Tables["deptnew"].Columns["deptid"], ds.Tables["patientnew"].Columns["deptid"]);
DropDownList1.DataSource = ds.Tables["deptnew"];
DropDownList1.DataValueField = "deptid";
DropDownList1.DataBind();
GridView1.DataSource = ds.Tables["doctornew"];
GridView1.DataMember = "deptdoct";
GridView1.DataBind();
GridView2.DataSource = ds.Tables["patientnew"];
GridView2.DataMember = "deptpatient";
GridView2.DataBind();
conn.Close();
}
}
}
dept table(parent table)
deptid deptname
10 cardiology
20 radiology
30 neurology
40 gastroenterology
50 ENT
doctor table(child table)
doctorid doctorname deptid
1 nanda 10
2 naidu 20
3 anji 30
4 govi 40
5 ramu 50
6 reddy 10
7 sathish 20
patient table(child table)
patientid patientname deptid
111 vivek 10
222 ramakrishna 20
333 vijay 30
444 manoj 40
555 paul 50
I established relation between tables using foreign key constraint.here problem is i bind the deptid column of dept table to dropdownlist control.now dropdownlist contain 10,20,30,40,50.when i select the dropdownlist 10 then it will display 10th department records like
deptid doctorid doctorname
10 1 nanda
10 6 reddy
as doctor table & 10th department records like
deptid patientid patientname
10 111 vivek
as patient table.but it is not coming .please solve the problem.waiting for your reply.thankyou.