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 (http://msdn.microsoft.com) 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.

Syntax

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

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

ItemName
The name to assign to the new item.

Return Value
A reference to a newly created object.

Example
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', ;
  'Access')
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'

VBScript

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", _
  "Access")
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

JavaScript

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' ;
}

C#

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;
}

VB.NET

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