Đang chuẩn bị liên kết để tải về tài liệu:
ASP.NET 4 Unleased - p 96

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Sau khi bạn đã thêm các loại, bạn có thể sử dụng nó giống như bất kỳ loại SQL Server bản địa khác. Ví dụ, bạn có thể tạo một bảng cơ sở dữ liệu mới với lệnh sau đây: CREATE TABLE DBMovies (ID INT IDENTITY, Phim DBMovie) | 924 CHAPTER 19 Building Data Access Components with ADO.NET Creating the User-Defined Type After you have loaded the DBMovie assembly you can create a new user-defined type from the assembly. Execute the following command CREATE TYPE dbo.DBMovie EXTERNAL NAME DBMovie.DBMovie If you need to delete the type you can execute the following command DROP TYPE DBMovie After you have added the type you can use it just like any other SQL Server native type. For example you can create a new database table with the following command CREATE TABLE DBMovies Id INT IDENTITY Movie DBMovie You can insert a new record into this table with the following command INSERT DBMovies Movie VALUES Star Wars George Lucas 12.34 Finally you can perform queries against the table with queries like the following SELECT Id Movie FROM DBMovies WHERE Movie.BoxOfficeTotals 13.23 SELECT MAX Movie.BoxOfficeTotals FROM DBMovies SELECT Movie FROM DBMovies WHERE Movie.Director LIKE g I find the fact that you can execute queries like this truly amazing. Building a Data Access Layer with a User-Defined Type In this final section let s actually do something with our new user-defined type. We create a new data access component that uses the DBMovie class and an ASP.NET page that interfaces with the component. Before we can do anything with the DBMovie type we need to add a reference to the DBMovie.dll assembly to our application. In Visual Web Developer select Website Add Reference and browse to the DBMovie.dll. Alternatively you can create an application root Bin folder and copy the DBMovie.dll into the Bin folder. Our new data access component is contained in Listing 19.37. LISTING 19.37 App Code DBDataLayer.cs using System using System.Data using System.Data.SqlClient using System.Web.Configuration using System.Collections.Generic From the Library of Wow eBook Building Database Objects with the .NET Framework 925 public class DBDataLayer private static readonly string _connectionString public List DBMovie .

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.