1、webservice中的去数据方法
[WebMethod(Description = "读取数据")] public XmlDataDocument GetMenuData() { DataSet ds = new DataSet(); //dt.TableName = "Column"; SqlConnection conn = new SqlConnection(@"Data Source=WWW-A576DBF2758\SQL2005;AttachDbFilename=E:\gao\gaosc\gaosc\App_Data\gaosc.mdf;Integrated Security=True;"); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select * from nz_Column"; SqlDataAdapter sda=new SqlDataAdapter(cmd.CommandText,conn); sda.Fill(ds); XmlDataDocument xd = new XmlDataDocument(ds); return xd; }
2、绑定数据控件
XmlDataDocument xd = new XmlDataDocument(); DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { WebApplication1.localhost1.GetData gd = new WebApplication1.localhost1.GetData(); XmlNode xnode; System.Text.StringBuilder sbuilder; xnode = gd.GetMenuData(); sbuilder = new System.Text.StringBuilder(xnode.OuterXml); xd.LoadXml(sbuilder.ToString()); ds.ReadXml(new XmlNodeReader(xd)); GridView1.DataSource = ds.Tables[0].DefaultView; GridView1.DataBind(); } }