The AddItem method adds a new DataSource object to the collection and returns a reference to the new object. You must specify the type of DataSource object to create, which must be one of:

  • VFP: a Visual FoxPro data source.

  • ODBC: an ODBC data source.

  • ADO: an ADO/OLE DB data source.

  • WebService: a data source accessed via a Web service.

  • SQLXML: a SQL Server data source accessed via HTTP. See the SQL Server Books Online or the MSDN Web site ( for information on SQLXML.

  • Text: comma-delimited text files. The name of the file must be in the Custom Properties property of each table in the data dictionary and the path must be in the Database property of the DataSource object.


AddItem(Type as String, ItemName as String) as Object

The type of DataSource object to create (see the list of choices above).

The name to assign to the new item.

Return Value
A reference to a newly created object.

This example, which could be used as the code for the GetDataSources script for a Database object, adds three data sources to the collection, two ODBC and one SQLXML.

Visual FoxPro

lparameters toApplication as SQApplication, toDatabase as Database
local loODBCDataSource as ODBCDataSource, ;
  loXMLDataSource as SQLXMLDataSource
loODBCDataSource = toDatabase.DataSources.AddItem('ODBC', ;
  'SQL Server')
loODBCDataSource.Driver   = 'SQL Server'
loODBCDataSource.Database = 'Northwind'
loODBCDataSource.Server   = '(local)'
loODBCDataSource.UserName = 'sa'
loODBCDataSource.Password = 'somepassword'
loODBCDataSource = toDatabase.DataSources.AddItem('ODBC', ;
loODBCDataSource.Driver   = 'Microsoft Access Driver (*.mdb)'
loODBCDataSource.Database = 'C:\MyData\NWIND.MDB'
loXMLDataSource = toDatabase.DataSources.AddItem('SQLXML', ;
  'SQL Server over HTTP')
loXMLDataSource.BaseURL = 'http://localhost/northwind'


function Main(Application, Database)
dim DataSource
set DataSource = Database.DataSources.AddItem("ODBC", _
  "SQL Server")
DataSource.Driver   = "SQL Server"
DataSource.Database = "Northwind"
DataSource.Server   = "(local)"
DataSource.UserName = "sa"
DataSource.Password = "somepassword"
set DataSource = Database.DataSources.AddItem("ODBC", _
DataSource.Driver   = "Microsoft Access Driver (*.mdb)"
DataSource.Database = "C:\MyData\NWIND.MDB"
set DataSource = Database.DataSources.AddItem("SQLXML", _
  "SQL Server over HTTP")
DataSource.BaseURL = "http://localhost/northwind"
end function


function Main(Application, Database) {
var DataSource ;
DataSource = Database.DataSources.AddItem('ODBC', 
  'SQL Server') ;
DataSource.Driver   = 'SQL Server' ;
DataSource.Database = 'Northwind' ;
DataSource.Server   = '(local)' ;
DataSource.UserName = 'sa' ;
DataSource.Password = 'somepassword' ;
DataSource = Database.DataSources.AddItem('ODBC', 
  'Access') ;
DataSource.Driver   = 'Microsoft Access Driver (*.mdb)' ;
DataSource.Database = "C:\MyData\NWIND.MDB" ;
DataSource = toDatabase.DataSources.AddItem('SQLXML', 
  'SQL Server over HTTP') ;
DataSource.BaseURL = 'http://localhost/northwind' ;


public static bool northwind_GetDataSources(SFQApplication sfqApplication, 
  Database database)
  DataSource datasource = database.DataSources.AddItem("ODBC", "SQL Server");
  datasource.Driver   = "SQL Server";
  datasource.Database = "Northwind";
  datasource.Server   = "(local)";
  datasource.UserName = "sa";
  datasource.Password = "somepassword";

  datasource = database.DataSources.AddItem("ODBC", "Access");
  datasource.Driver   = "Microsoft Access Driver (*.mdb)";
  datasource.Database = @"C:\MyData\NWIND.MDB";

  datasource = database.DataSources.AddItem("SQLXML", "SQL Server over HTTP");
  datasource.BaseURL = "http://localhost/northwind";
  return true;


public shared function northwind_GetDataSources(sfqApplication as SFQApplication, _
  database as Database) as Boolean
  Dim datasource as DataSource = database.DataSources.AddItem("ODBC", "SQL Server")
  datasource.Driver   = "SQL Server"
  datasource.Database = "Northwind"
  datasource.Server   = "(local)"
  datasource.UserName = "sa"
  datasource.Password = "somepassword"

  datasource = database.Datasources.AddItem("ODBC", "Access")
  datasource.Driver   = "Microsoft Access Driver (*.mdb)"
  datasource.Database = "C:\MyData\NWIND.MDB"

  datasource = database.DataSources.AddItem("SQLXML", "SQL Server over HTTP")
  datasource.BaseURL = "http://localhost/northwind"

  return true
End Function

See also

AddItem | DataSources Collection

© Stonefield Software Inc., 2023 • Updated: 06/06/16
Comment or report problem with topic