TAILIEUCHUNG - 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 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.