首页 > 代码库 > 数据绑定到ADO.NET
数据绑定到ADO.NET
// De?ne a DataSet with a single DataTable.DataSet dsInternal = new DataSet();dsInternal.Tables.Add("Users"); // De?ne two columns for this table.dsInternal.Tables["Users"].Columns.Add("Name");dsInternal.Tables["Users"].Columns.Add("Country"); // Add some actual information into the table.DataRow rowNew = dsInternal.Tables["Users"].NewRow();rowNew["Name"] = "John";rowNew["Country"] = "Uganda";dsInternal.Tables["Users"].Rows.Add(rowNew); rowNew = dsInternal.Tables["Users"].NewRow();rowNew["Name"] = "Samantha";rowNew["Country"] = "Belgium";dsInternal.Tables["Users"].Rows.Add(rowNew); rowNew = dsInternal.Tables["Users"].NewRow();rowNew["Name"] = "Rico";rowNew["Country"] = "Japan";dsInternal.Tables["Users"].Rows.Add(rowNew);// De?ne the binding.lstUser.DataSource = dsInternal.Tables["Users"];lstUser.DataTextField = "Name";//或者// De?ne the binding.lstUser.DataSource = dsInternal;lstUser.DataMember = "Users";lstUser.DataTextField = "Name";//this.DataBind();
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。