如何用Object数据源绑定数据对象 按照书上的讲解,先添加一个class文件,输入代码 using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.ComponentModel;
namespace DataSourceDemo { /// <summary> ///操作NorthwindUserInfo 数据库的userinfo表 /// </summary> public class NorthwindUserInfo { /// <summary> ///获取所有用户信息列表 /// </summary> /// <returns> </returns> [DataObjectMethod(DataObjectMethodType.Select)] public static DataTable GetAllUser() { SqlConnection conn; try { string sqlCommand = "select * from userinfo"; conn=new SqlConnection(GetConnectionString()); SqlDataAdpter da = new SqlDataAdpter(sqlCommand,conn); DataSet ds = new DataSet(); conn.open(); da.Fill(ds,"userinfo"); return ds.Tables["userinfo"]; } catch { return null; }