Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Friday, December 17, 2010

Data Relation Through DataSet

SqlConnection con=new SqlConnection (ConfigurationManager.ConnectionStrings["kumarConnectionString"].ConnectionString);

protected void Button1_Click1(object sender, EventArgs e)
{


DataSet ds = new DataSet();
string firstSql = null;

//connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
firstSql = "select * from emp;";
firstSql += "select * from dep";


try
{
SqlCommand cmd = new SqlCommand(firstSql, con);
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(ds);
//creating data relations
DataRelation relation;
DataColumn table1Column;
DataColumn table2Column;
//retrieve column
table1Column = ds.Tables[0].Columns[0];
table2Column = ds.Tables[1].Columns[0];
//relating tables
relation = new DataRelation("relation", table1Column, table2Column);
//assign relation to dataset
ds.Relations.Add(relation);
Response.Write("Data relation completed");

}
catch (Exception ex)
{
Response.Write("Can not open con ! ");

}
}

Reading Xml file and fill dropdown....

XmlNode eleDestNodeLists;
string FilePath = Request.PhysicalApplicationPath + @"Configuration\" + "UserInfo.xml";
XmlDocument docSource = new XmlDocument();
docSource.Load(FilePath);
Int32 assetid = Convert.ToInt32(Session["assetid"].ToString());
string sbookCode = Session["bookCode"].ToString();
eleDestNodeLists = docSource.SelectSingleNode("/UserInfo/Asset[@assetid='" + assetid + "' and @BookCode='" + sbookCode.ToString() + "']");
foreach (XmlNode xn in eleDestNodeLists.ChildNodes)
{
string abbreviation = xn.Attributes.GetNamedItem("abbreviation").Value;
string id = xn.Attributes["id"].Value;
ddlRole.Items.Add(new ListItem(abbreviation, id));
Page.ClientScript.RegisterStartupScript(typeof(Page), "FillUserName", "setTimeout(\"FillUserName()\",1000);", true);
}