Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'learn financial modeling markets using visual basic net_7', công nghệ thông tin, hệ điều hành phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Structured Query Language 233 The UNION Keyword A UNION is useful if you want to get data from two tables within the same result set. For example if we want to see the bid and ask for INTC as well as the bids and asks for all the INTC options in one result set the SQL statement would read as follows Select StockSymbol Bid Ask FROM Stock WHERE StockSymbol IBM UNION Select OptionSymbol Bid Ask FROM Optioncontracts WHERE StockSymbol IBM See Figure 13.6. The data type for the columns in each SELECT statement must match for a UNION to work. This is not an issue in the above example because each of the tables has identical column sets. The INSERT Statement Up to this point we have only queried the Options.mdb database and looked at the results. We may however also be interested in changing the data. In order to add delete or modify the data in the FIGURE 13.6 Team-LRN 234 Database Programming Options.mdb database we will first need to add some elements to our SQLexample program. Step 5 Add another button to your form. Step 6 Add the following code to the Button2_Click event Private Sub Button2_Click ByVal sender As . Handles Button2.Click Try myConnect.Open Dim command As New OleDbCommand TextBox1.Text myConnect command.ExecuteNonQuery Catch MsgBox Please enter a valid SQL statement. Finally myConnect.Close End Try End Sub An OleDbCommand object is an SQL statement that we can use to perform transactions against a database. We use the ExecuteNonQuery member method to execute UPDATE INSERT and DELETE statements. For the remainder of the chapter SELECT statements should be executed using the first button and all other transactions should be executed using this new second button. The SQL INSERT statement enables us to add data to a table in a database. Here is an example showing the syntax for adding a record to the OptionTrades table INSERT INTO OptionTrades TradeDateTime OptionSymbol BuySell Price Quantity TradeStatus VALUES 02 27 2003 IBMDP B 2.60 10 F You can verify .