阅读:2140回复:2
数据库绑定方法
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" border=0>
<TR> <TD vAlign=top>下列代码实现了类似地理匹配的功能。即TAB与DataBase中有一字段相同,将二者关联起来。(采用ODBC,DAO,ADO三种方式) 注意:别忘记引用对象库. Private Sub cmdCustom_Click() 'Add the single layer Map1.Layers.RemoveAll Map1.Layers.Add App.Path ; "\import.tab" 'make the map look nice for the sample data Map1.DisplayCoordSys = Map1.NumericCoordSys Map1.Title.Visible = False Map1.Bounds = Map1.Layers.Item("import").Bounds Map1.Zoom = Map1.Zoom * 2 Clickable (True) End Sub Private Sub cmdQuit_Click() End End Sub Private Sub Command1_Click() Dim ds As MapXLib.Dataset Dim flds As New MapXLib.Fields 'requires reference t "MapX ODBC Dataset Engine Library" 'and an ODBC DSN named import needs to be linked to import.mdb Dim parm As New ODBCQueryInfo parm.SqlQuery = "Select * from table1" parm.DataSource = "import" 'DSN pointing to Mapstats.mdb parm.ConnectString = "ODBC;" ' Get the relevant fields that'll come from DB flds.Add "DB1", "DB1", miAggregationIndividual, miTypeString flds.Add "DB2", "DB2byODBC", miAggregationIndividual, miTypeString 'Make Dataset Set ds = Map1.Datasets.Add(miDataSetODBC, parm, "importODBC", "DB1", , "import", flds) 'make the theme ds.Themes.Add miThemeAuto Clickable (False) End Sub Private Sub Command2_Click() Dim ds As MapXLib.Dataset Dim flds As New MapXLib.Fields 'requires reference t "Microsoft DAO Object Library" Dim db As Database Dim rs As Recordset 'open Database and recordset Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path ; "/import.mdb") Set rs = db.OpenRecordset("table1") 'define the fields flds.Add "DB1", "DB1", miAggregationIndividual, miTypeString flds.Add "DB2", "DB2byDAO", miAggregationIndividual, miTypeString 'add the dataset Set ds = Map1.Datasets.Add(miDataSetDAO, rs, "importDAO", "DB1", , "import", flds) 'make theme and close out ds.Themes.Add miThemeAuto rs.Close db.Close Clickable (False) End Sub Private Sub Command3_Click() Dim ds As MapXLib.Dataset Dim flds As New MapXLib.Fields 'requires reference to Microsoft ActiveX Data Objects Library Dim rs As New ADODB.Recordset Dim Conn As New ADODB.Connection Conn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;" ; "Data Source=" ; App.Path ; "\import.mdb") rs.CursorLocation = adUseClient rs.Open "SELECT * FROM table1 ", Conn 'define the fields flds.Add "DB1", "DB1", miAggregationIndividual, miTypeString flds.Add "DB2", "DB2byADO", miAggregationIndividual, miTypeString 'add dataset Set ds = Map1.Datasets.Add(miDataSetADO, rs, "importADO", "DB1", , "import", flds) 'make theme ds.Themes.Add miThemeAuto Clickable (False) End Sub Private Sub Form_Load() Clickable (False) End Sub Public Sub Clickable(ByVal b As Boolean) Command1.Enabled = b Command2.Enabled = b Command3.Enabled = b End Sub<!-- viewthread_post_sig --> </TD></TR> <TR> <TD vAlign=bottom> <HR align=left width="50%" color=#ffffff noShade SIZE=0> </TD></TR></TABLE> |
|
1楼#
发布于:2004-10-09 09:48
<P>应该贴一点注释</P><img src="images/post/smile/dvbbs/em01.gif" />
|
|
2楼#
发布于:2004-10-10 06:00
study
|
|