tailieunhanh - ASP.NET 4 Unleased - p 91

Trả về một giá trị đơn Nếu bạn cần phải trả lại một giá trị duy nhất từ một truy vấn cơ sở dữ liệu, bạn có thể sử dụng () phương pháp. Phương pháp này luôn luôn trả về giá trị của cột đầu tiên từ dòng đầu tiên của một tập kết quả. Ngay cả khi một truy vấn trả lại hàng trăm cột và hàng tỷ hàng, mọi thứ đều bị bỏ qua trừ giá trị của cột đầu tiên của hàng đầu tiên | 874 CHAPTER 19 Building Data Access Components with div form body html Returning a Single Value If you need to return a single value from a database query you can use the method. This method always returns the value of the first column from the first row of a resultset. Even when a query returns hundreds of columns and billions of rows everything is ignored except for the value of the first column from the first row. For example the page in Listing contains a lookup form. If you enter the title of a movie the movie s total box office returns display in a Label control see Figure . FIGURE Retrieving a value with ExecuteScalar . LISTING @ Page Language C @ Import Namespace @ Import Namespace @ Import Namespace DOCTYPE html PUBLIC - W3C DTD XHTML Transitional EN From the Library of Wow eBook Connected Data Access 875 http TR xhtml1 DTD script runat server protected void btnSearch_Click object sender EventArgs e string connectionstring Movies .ConnectionString SqlConnection con new SqlConnection connectionString SqlCommand cmd new SqlCommand SELECT BoxOfficeTotals FROM Movies WHERE Title @Title con @Title using con Object result if result null 0 c result else No match script html xmlns http 1999 xhtml head id Head1 runat server title Show Execute Scalar title head body form id form1 runat server div h1 Box Office Totals h1 asp Label id lblTitle Text Movie Title AssociatedControlID txtTitle Runat server asp TextBox id txtTitle Runat server asp Button id btnSearch 19 From the Library of Wow eBook 876 CHAPTER 19 Building Data Access Components with Text Search OnClick btnSearch_Click Runat server hr asp Label id lblResult Runat

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.