using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Sql; using System.Data.SqlClient; using System.Data; using System.Xml; using System.IO; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ReadXMLSetting("sqlconn", false)); try { if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand(ReadXMLSetting("sqlquery", false), con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet dstTables = new DataSet(); da.Fill(dstTables); if (dstTables != null && dstTables.Tables[0] != null && dstTables.Tables[0].Rows.Count > 0) { GRD.DataSource = dstTables.Tables[0]; GRD.DataBind(); } else { GRD.DataBind(); } } catch (Exception ex) { } finally { if (con.State == ConnectionState.Open) { con.Close(); } } } public static string ReadXMLSetting(string Key, bool ReturnPath) { string SMapPath = HttpContext.Current.Server.MapPath("~/App_Data/"); string filePath = SMapPath + "Setting.xml"; string value = ""; XmlDocument XD = new XmlDocument(); if (File.Exists(filePath)) { XD.Load(filePath); XmlNode node = XD.SelectSingleNode("setting/add" + "[@key='" + Key + "']"); value = node.Attributes["value"].Value; } if (ReturnPath == true) { return HttpContext.Current.Server.MapPath(value); } else { return value; } } }