Automatically Updating the Data Source
In This Topic
This topic illustrates how to create an editable grid using templates and a DataSource control. Complete the following steps:
- Create a grid and bind it to a DataSource control; see Binding the Grid to a Data Source topic for details. Use the Suppliers table in the Northwind database and retrieve the SupplierID, CompanyName, ContactName, and Address fields.
- Configure UpdateQuery:
- Right-click the AccessDataSource1 component and then click Properties. In the Properties tab click the ellipsis button next to UpdateQuery. The Command and Parameter Editor dialog box appears.
- Click Query Builder, select the Suppliers table and click Add.
- Insert the following text in UPDATE command and click OK to close the Query Builder:
UPDATE Suppliers SET CompanyName = ?, ContactName = ?, Address = ? WHERE (SupplierID = ?)
- Click the Add Parameter button and rename the parameter "SupplierID".
- Click Show advanced properties and set the Type property to Int32.
- In the same way, add CompanyName, ContactName, Address parameters, but set their Types to String.
- Click OK to close the Command and Parameter Editor dialog box.
- Right-click the C1GridView control and then click Show Smart Tag.
- On the C1GridView Tasks menu, in the Choose Data Source box, click AccessDataSource1, if necessary.
- Right-click the C1GridView control and click Properties. In the Properties window set the DataKeyNames value to SupplierID.
- In the Properties window, set the AllowClientEditing property to True.
See Also
Binding the Grid to a Data Source