TAILIEUCHUNG - Professional ASP.NET 1.0 Special Edition- P44
Professional Special Edition- P44:Those of us who are Microsoft developers can't help but notice that .NET has received a fair amount of visibility over the last year or so. This is quite surprising considering that for most of this period, .NET has been in its early infancy and beta versions. I can't remember any unreleased product that has caused this much interest among developers. And that's really an important point, because ignoring all the hype and press, .NET really is a product for developers, providing a great foundation for building all types of applications | products products return products public DataSet GetProductCategories SqlConnection myConnection new SqlConnection m_ConnectionString SqlDataAdapter sqlAdapterl new SqlDataAdapter SELECT DISTINCT ProductType FROM Products myConnection DataSet products new DataSet products products return products This class has four methods including the constructor ProductsDB - Initializes the class with a data source string. GetProduct - Returns a dataset containing details for a single product. GetProducts - Returns a dataset containing the details for all products in a specified category. GetProductCategories - Returns a dataset containing the list of product categories. The first three lines of the component declare the namespaces we are using using System using using All of our class files have these lines and they indicate that we are using the standard system namespace the namespaces for and the SQL Server-specific parts of . We use the SQL Server-specific elements of because they provide high performance SQL Server access using TDS Tabular Data Stream via the classes SqlConnection and SqlDataAdapter. If we needed to support a different back-end database we could recode our classes to use the OleDbConnection and OleDbDataAdapter classes which perform database access through OLEDB. These classes were discussed in Chapter 8. One important point to note about all of the code in the business object is that it does not contain any exception handlers. It is therefore up to the code that uses these classes to catch exceptions like SqlException which can be thrown if any error occurs when performing the data access such as the existence of duplicate rows and so on We haven t included any exception handling in our pages to keep them terse but the basic format is shown here try catch SqlException e if 2627 .
đang nạp các trang xem trước