Database Reference
In-Depth Information
InsertCommand Property
The data adapter uses the
InsertCommand
property for inserting rows into a table. Upon calling the
Update
method, all rows added to the data table will be searched for and propagated to the database.
Try It: Propagating New Data Set Rows to a Data Source
Let's propagate a new row to the database, in another variation on
ModifyDataTable.cs
in Listing 15-5.
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
PersistAdds.cs
. Click OK to add this form to
the DataSetandDataAdapter project.
2.
Select the PersistAdds form by clicking the form's title bar, and set the Size
property's Width to 452 and Height to 163.
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 412 and Height to 95.
•
Leave the Text property blank.
4.
Now your PersistAdds form in the Design view should look like Figure 15-11.
Figure 15-11.
The Design view of the PersistAdds form
5.
Double-click the empty surface of the
PersistAdds.cs
form, and it will open
the code editor window, showing the
PersistAdds _Load
event. Modify the
PersistAdds _Load
event to look like Listing 15-5.