tailieunhanh - Beginning C# 2005 Databases PHẦN 3

Trên trang này, bạn chọn kiểu lệnh truy vấn cần thực hiện. Bạn có thể chọn: ❑ Sử dụng SQL cáo: Cho phép bạn tạo ra bất kỳ truy vấn SQL bạn có thể miễn là nó trả về hoặc không có kết quả hoặc kết quả duy nhất. Bạn cũng có thể cung cấp một truy vấn tham số mà bạn có thể vượt qua giá trị được sử dụng bởi các truy vấn (ví dụ như ID | Chapter 3 Figure 3-9 Choosing a query command type On this page you select the type of command that the query should execute. You can choose Use SQL Statements Enables you to create any SQL query you might like to as long as it returns either no result or a single result. You can also provide a parameterized query by which you can pass values to be used by the query such as the ID of a row to delete in a delete query . Create New Stored Procedure Similar to the preceding option but the SQL you enter is used to create a stored procedure that is then accessed directly by the Query item. These also can be parameterized. Use Existing Stored Procedure Creates a command that calls an existing stored procedure in the database parameterized or not. Care should be taken here to use a stored procedure that returns no results or a single value otherwise you cannot predict what you ll receive as a return value. For the first two options the next stage is to choose the type of SQL statement you are creating as shown in Figure 3-10. As you can see the only option unavailable is Select Which Returns Rows. You can however create any other type of SQL statement. The next step for a SQL command or stored procedure based on a SQL command is to enter the text of the command itself. You can either do that manually or use the SQL command builder which enables you to design queries graphically. If you want to parameterize your queries you can supply variable names in the form @ Variable Name 80 Viewing Data Figure 3-10 Choosing a query type For example you could make a query as follows SELECT Stringcolumn FROM MyTable WHERE MyTableld @MyTableId This would return the value for a single column in a single row where the row is identified by an ID value specified as a parameter called @MyTableId. If you are using an existing stored procedure you are presented with a drop-down selector from which to choose a stored procedure to use. Then you will see the parameters that will be generated and