——————————————————————————————————————————
1. SQLDataSource, AccessDataSource这二种数据控件用法差不多
MSDN:
public class AccessDataSource : SqlDataSource
SQLDataSource简单用法:
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [Region]"
</asp:SqlDataSource>
只要设置ConnectionString和SelectCommand就可以了。然后与数据绑定控件进行绑定。简单。ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT * FROM [Region]"
</asp:SqlDataSource>
——————————————————————————————————————————
AccessDataSource简单用法:
<asp:AccessDataSource
ID="AccessDataSource1"
runat="server"
DataFile="~/App_Data/Northwind.mdb"
SelectCommand="SELECT * FROM [Categories]">
</asp:AccessDataSource>
多了一个DataFile存放Access文件的路径。ID="AccessDataSource1"
runat="server"
DataFile="~/App_Data/Northwind.mdb"
SelectCommand="SELECT * FROM [Categories]">
</asp:AccessDataSource>
——————————————————————————————————————————
.NET 2.0里面这几个数据绑定控件可以在工具栏托到界面上直接使用。还可以在代码中进行声明使用
1SqlDataSource sql = new SqlDataSource();
2 sql.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;
3 sql.DataSourceMode = SqlDataSourceMode.DataSet;
4 sql.SelectCommandType = SqlDataSourceCommandType.Text;
5
6 sql.SelectCommand = "select * from authors";
7 GridView1.DataSource = sql.Select(DataSourceSelectArguments.Empty);
8 GridView1.DataBind();
9
2 sql.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["pubsConnectionString"].ConnectionString;
3 sql.DataSourceMode = SqlDataSourceMode.DataSet;
4 sql.SelectCommandType = SqlDataSourceCommandType.Text;
5
6 sql.SelectCommand = "select * from authors";
7 GridView1.DataSource = sql.Select(DataSourceSelectArguments.Empty);
8 GridView1.DataBind();
9
——————————————————————————————————————————
2.ObjectDataSource较之前几个控件更适用于比较灵活和松散的一些操作上,ObjectDataSource可以与具体的业务对象也就是逻辑层对象进行绑定,有CRUD四种方法,分别与业务对象上的方法对应,其中有什么制约看下ObjectDataSource配置数据源有简单的说明。
......................................
......................................
......................................
也就是说ObjectDataSource可以把业务逻辑层与表示层或数据显示控件很好的连接起来,是业务逻辑层是表示层中间的一个桥梁。