Database Reference
In-Depth Information
Note For a command builder to work, the SelectCommand data adapter property must contain a query that
returns either a primary key or a unique key for the database table. If none is present, an InvalidOperation
exception is generated, and the commands aren't generated.
Try It: Using SqlCommandBuilder
Here, you'll use SqlCommand Builder to insert a row into the database.
1. Select the DataSetandDataAdapter project, right-click, and choose Add
Windows Form. From the opened dialog, make sure the Windows form is
selected, and rename Form1.cs to PersistAddsBuilder.cs . Click OK to add this
form to the DataSetandDataAdapter project.
2. Select the PersistAddsBuilder form by clicking the form's title bar, and set the
Size property's Width to 483 and Height to 151.
3. Drag a TextBox control to the form, and position it toward the center of the
form. Select this TextBox control, navigate to the Properties window, and set
the following properties:
Set the Name property to txtDepartment.
For the Location property, set X to 12 and Y to 12.
For the Size property, set Width to 441 and Height to 89.
Leave the Text property blank.
4. Now your PersistAddsBuilder form in the Design view should look like
Figure 15-13.
Figure 15-13. The Design view of the PersistAddsBuilder form
5. Double-click the empty surface of the PersistAddsBuilder.cs form, and it will
open the code editor window, showing the PersistAddsBuilder _Load event.
Modify the PersistAddsBuilder _Load event to look like Listing 15-6.
 
Search WWH ::




Custom Search