set default value by sql command in DataForm - DataForm.NET Samples

This example shows how to use a sql command to retrieve a single value from a table/view by referencing a value from a field of current DataForm. In this example, field SupplierName and CategoryName are from Suppliers table and Categories table.

Pick a Theme:

ProductID1ProductName
SupplierIDSupplier Name
CategoryIDCategory Name
QuantityPerUnitUnitPrice
UnitsInStockUnitsOnOrder
ReorderLevelDiscontinued

  Design   Source  
  1. Open DataForm.NET Manager. In DataForm.NET List page, choose Products by clicking the link.
  2. In the DataForm.NET Designer on the right hand side, the default tab is DataForm tab.
  3. Add a "SupplierName" field to the DataForm. Then click "SupplierName" link to bring up a DataForm Field Designer window.
  4. Switch to Default Value tab, specify the Default Type as SQL Command. Enter sql command, "select Companyname from suppliers where supplierid={dataform!SupplierID}", to the big Default Value text box. {dataform!SupplierID} means it will get a value from SupplierID field. To use the other options to generate default value, please see Default Value
  5. Repeat the step 3 and 4 to add "CategoryName" field, but change the sql command to "select categoryname from categories where categoryid={dataform!categoryid}"
  • Click HERE to open up a READ ONLY DataForm.NET Manager.
  • Click HERE to try for yourself.