Visual Studio 2005 整合資料庫管理工具,配合 ASP.NET 2.0 新世代資料源控制項(SqlDataSource、ObjectDataSource)與資料繫結控制項(GridView、DetailsView、FormView),實現「零程式碼」資料庫應用開發。
.\SQLEXPRESS)、認證、資料庫。.xsd)。TableAdapter、DataTable、TableAdapterManager。Select、Insert、Update、Delete 命令,支援參數化查詢與預存程序。DataSet 類別,提供 IntelliSense、編譯期型別檢查。<asp:SqlDataSource ID="ProductsDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:NWConnectionString %>"
SelectCommand="SELECT ProductID, ProductName, UnitPrice FROM Products"
DeleteCommand="DELETE FROM Products WHERE ProductID = @ProductID"
UpdateCommand="UPDATE Products SET ProductName=@ProductName, UnitPrice=@UnitPrice WHERE ProductID=@ProductID"
InsertCommand="INSERT INTO Products (ProductName, UnitPrice) VALUES (@ProductName, @UnitPrice)">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" DataSourceID="ProductsDataSource"
DataKeyNames="ProductID" AutoGenerateColumns="False"
AllowPaging="True" AllowSorting="True" AllowEditing="True" AllowDeleting="True">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="ID" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="ProductName" HeaderText="產品名稱" SortExpression="ProductName" />
<asp:BoundField DataField="UnitPrice" HeaderText="單價" SortExpression="UnitPrice" DataFormatString="{0:C}" />
<asp:CommandField ShowEditButton="True" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
DataKeyNames 對應更新/刪除鍵值,模板欄位雙向繫結自動收集輸入值。web.config <connectionStrings>,部署環境切換零修改程式碼。大型專案建議使用 ObjectDataSource 繫結中間層業務元件(DAL/BLL),分離關注點,利於測試與維護。TableAdapter 產生的類別即可作為資料存取層元件。
VS 2005 與 ASP.NET 2.0 資料工具將資料庫開發從繁瑣程式碼解放,讓開發者專注於業務邏輯與使用者體驗設計。