Create table Customer(custid int primary key, custname varchar(100))
insert into Customer values(1,'swapnil')
insert into Customer values(2,'Anil')
insert into Customer values(3,'jaydeep')
create table custtransactions( amount int, custid int constraint fk1 foreign key references Customer(custid))
insert into custtransactions values(1,1000)
insert into custtransactions values(1,1200)
protected void Page_Load(object sender, EventArgs e)
{
cmd= new SqlCommandBuilder(da);
da.SelectCommand = new SqlCommand();
string str = WebConfigurationManager.ConnectionStrings["constr"].ToString();
Response.Write(str);
da.SelectCommand.Connection = new SqlConnection(str) ;
da.SelectCommand.CommandText = "select * from customers";
da.Fill(ds, "customers");
da.SelectCommand.CommandText = "select * from custtransactions";
da.Fill(ds, "custtransactions");
}
protected void Button3_Click(object sender, EventArgs e)
{
DataRelation mycust =ds.Relations.Add("custtrans",ds.Tables[0].Columns["custid"], ds.Tables[1].Columns["custid"]);
foreach (DataRow custRow in ds.Tables[0].Rows)
{
Response.Write("<p style='color:blue;font-size:2em'>");
Response.Write(custRow["custid"].ToString());
foreach (DataRow trans in custRow.GetChildRows(mycust))
{
Response.Write("<p style='color:green;font-size:2em'>");
Response.Write(trans["amount"].ToString());
Response.Write("<br/>");
Response.Write(trans["transactiondate"].ToString());
Response.Write("</p>");
}
Response.Write("<hr/>");
}
}
No comments:
Post a Comment