Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (16.6 KB, 3 trang )
4.4 Create and Execute On-the-Fly Batch Updates by Using ADO.NET
Sometimes in database applications, you want to create and execute stored procedures
that don't currently exist. When you have a situation in which you need to use highly
dynamic stored procedures that might use criteria that is entirely created at runtime, you
might need to create those stored procedures on-the-fly. This How-To shows you how to
create and execute these stored procedures.
It's great that you can execute stored procedures that are already created, but what if you
need to generate one at runtime? How do you do this?
Technique
To perform this How-To, you will be utilizing the OleDBCommand object, and feeding
in the CommandText property from a text box. The text box is set to "Update Employees
Set City = 'Redmond' Where City = 'Seattle'" to give you something to start with.
Steps
Open and run the VB.NET-Chapter 4 solution. From the main form, click on the
command button with the caption How-To 4.4. When the form loads, you will see an
example update statement in a text box. Click on the Execute button to execute the update
statement. A TextBox control is then displayed on the bottom of the form showing the
number of records that are affected. You can the form in Figure 4.3.
Figure 4.3. This form uses the Command object with a SQL statement passed to
execute the specified action.
Note
The number of records affected might be different on your system
depending on what you have been doing with the Northwind data.
1. Create a new Windows Form.
2. Add the following controls, setting the properties as listed in Table 4.6.
Table 4.6. Controls Property Settings
Object Property Setting
Label Name