Database Exchange > Using MS SQL Server 2000 as a Data Source > Using a Table or View as a Record Source

Using a Table or View as a Record Source

Using a table or view as a record source is straightforward. You select a table or view from the Data Table list and click Apply. This example shows how to change tables at runtime.

To use a table or view as a record source:

  1. Copy and paste the following example code to your Cicode file

FUNCTION GenerateTableList()
INT iIndex;
STRING sItemName;
iIndex = 0;
WHILE iIndex < 6 DO
SELECT CASE iIndex
CASE 0
sItemName = "Employees";
CASE 1
sItemName = "Orders";
CASE 2
sItemName = "Customers";
CASE 3
sItemName = "Categories";
CASE 4
sItemName = "Products";
CASE 5
sItemName = "Order Details";
END SELECT
_OBJECT CallMethod(ObjectByName("AN36"), "AddItem", sItemName, iIndex);
iIndex = iIndex + 1;
END
END

FUNCTION RECIPE_AN36_Click(OBJECT this)
STRING sTableName;
sTableName = _ObjectGetProperty(This, "Text");
IF (sTableName > "") THEN
_ObjectSetProperty(ObjectByName("AN35"), "RecordSource1", sTableName);
END
END

  1. Insert a Microsoft Form 2.0 list box on page “Recipe”. This control is used to list tables that will be cooperated with the Database Exchange control on the page. It is assumed that the list box control occupies AN36.
  2. Add a button to the graphics page and enter the following code in the Input text box.

GenerateTableList();

  1. Compile and run. At runtime, click the button to generate a table list.
  2. Clicking an item on the list box populates a new table on the Database Exchange control.