tailieunhanh - ASP.NET 4 Unleased - p 82

Using the ObjectDataSource Control public void UpdateMovie(int id, string title, string director, DateTime ➥dateReleased) { // Create Command SqlConnection con = new SqlConnection(_conString); SqlCommand cmd = new SqlCommand(); = con; = “UPDATE Movies SET Title=@Title,Director=@Director,DateReleased= // Add parameters (“@Title”, title); (“@Director”, director); (“@DateReleased”, dateReleased); (“@Id”, id); // Execute command using (con) { (); (); } } public SqlDataReader GetMovies() { // Create Connection SqlConnection con = new SqlConnection(_conString); // Create Command SqlCommand cmd = new SqlCommand(); = con; = “SELECT Id,Title,Director,DateReleased FROM Movies”; // Return DataReader (); return. | 784 CHAPTER 18 Using the ObjectDataSource Control public void UpdateMovie int id string title string director DateTime dateReleased Create Command SqlConnection con new SqlConnection _conString SqlCommand cmd new SqlCommand con UPDATE Movies SET Title @Title Director @Director DateReleased Add parameters @Title title @Director director @DateReleased dateReleased @Id id Execute command using con public SqlDataReader GetMovies Create Connection SqlConnection con new SqlConnection _conString Create Command SqlCommand cmd new SqlCommand con SELECT Id Title Director DateReleased FROM Movies Return DataReader return public Movies _conString Movies .ConnectionString From the Library of Wow eBook Using Parameters with the ObjectDataSource Control 785 The page in Listing contains a GridView and ObjectDataSource control. The ObjectDataSource control includes an UpdateMethod property that points to the UpdateMovie method. LISTING @ Page Language C DOCTYPE html PUBLIC - W3C DTD XHTML EN http TR xhtml11 DTD html xmlns http 1999 xhtml head id Head1 runat server title Show Movies title head body form id form1 runat server div asp GridView id grdMovies DataSourceID srcMovies DataKeyNames Id AutoGenerateEditButton true Runat server asp ObjectDataSource id srcMovies TypeName Movies SelectMethod GetMovies UpdateMethod UpdateMovie Runat server div form body html 18 In Listing the GridView automatically adds the update parameters to the ObjectDataSource control s UpdateParameters collection. As an alternative you can declare the parameters used by the ObjectDataSource control explicitly. For example the page in .

TÀI LIỆU LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.