袁绍伦
路人甲
路人甲
  • 注册日期2003-08-08
  • 发帖数654
  • QQ164646905
  • 铜币1336枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1462回复:0

Delphi Example of an ODBC Dataset

楼主#
更多 发布于:2003-09-03 21:42
procedure TMapForm.ODBCButtonClick(Sender: TObject);
var
 ds: Dataset;
 parm: Variant;
 fields: CMapXFields;
begin
 try
  { CreateOleObject is found in the 'ComObj' package }
  parm := CreateOleObject('MapX.ODBCQueryInfo.4');
 parm.SqlQuery := 'select * from USA';

  { if the ConnectString is left blank, the user will be
    prompted to find a driver and data source. This can
    include uid=, pwd=, and dlg= fields.
    Change the DBQ= line if MapX was installed in another
    location. }

  parm.ConnectString := 'ODBC;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=C:\Program Files\MapInfo\MapX 5.0\Data\MapStats.mdb;';
  { Rather than providing connection information in the
    connect string, a named data source can be created in the
    ODBC Data Sources Control Panel and used here. }
  parm.DataSource := '';

  { Describe the structure of the Database. Here, we only
    bring in the 3 fields that we need. }
  fields := CoFields.Create;
  fields.Add('GEOABBR', 'GEOABBR', miAggregationAuto, miTypeString);

  fields.Add('GEONAME', 'GEONAME', miAggregationAuto, miTypeString);
  fields.Add('TOTPOP', 'TOTPOP', miAggregationAuto, miTypeNumeric);

  { Add the Dataset. }
  ds := Map1.Datasets.Add(miDataSetODBC, parm, 'ODBC Dataset',EmptyParam, EmptyParam, 'USA', fields, EmptyParam);

  { Create the default theme on the dataset. This will be a
    ranged theme on the TOTPOP field. }
  ds.Themes.Add(EmptyParam, EmptyParam, EmptyParam, EmptyParam);
 except
  on E: EOleException do

   Application.MessageBox(PChar(E.Message), 'Error', MB_OK or MB_ICONERROR);
 end;
end;
喜欢0 评分0
愿意和大家交朋友! QQ:47559983 MSN:shaolun_yuan@hotmail.com eMail:shaolun-yuan@163.com
游客

返回顶部