Dim cn As ADODB.Connection '创建ADO连接并打开 Sub CreateConnection() Dim ConStr As String '连接字符串 Set cn = New ADODB.Connection cn.CursorLocation = adUseClient cn.Provider = "Microsoft.Jet.OLEDB.4.0;" ConStr = "Data Source=你的数据库文件;" cn.Open ConStr End Sub
' 从数据库中读取数据 Public Sub ReadFromDB() ' 创建数据库连接 Call CreateConnection ' 在line表中查询所有的记录 Set rst = New ADODB.Recordset rst.CursorLocation = adUseClient rst.Open "SELECT DISTINCT * FROM line", cn, adOpenForwardOnly, _ adLockBatchOptimistic, adCmdText rst.MoveFirst Dim i As Integer Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double ' 使用查询得到的数据创建直线 For i = 0 To rst.RecordCount - 1 pt1(0) = rst.Fields("x1") pt1(1) = rst.Fields("y1") pt1(2) = 0 pt2(0) = rst.Fields("x2") pt2(1) = rst.Fields("y2") pt2(2) = 0 ThisDrawing.ModelSpace.AddLine pt1, pt2 rst.MoveNext Next i 'rst.Close ' 关闭记录集,准备下一次使用 ' 在line表中查询 Set rst = New ADODB.Recordset rst.CursorLocation = adUseClient rst.Open "SELECT x1,y1 FROM line", cn, adOpenForwardOnly, _ adLockBatchOptimistic, adCmdText rst.MoveFirst ' 使用表中的数据绘制圆 For i = 0 To rst.RecordCount - 1 pt1(0) = rst.Fields("x1") pt1(1) = rst.Fields("y1") pt1(2) = 0 ThisDrawing.ModelSpace.Addpoint rst.MoveNext Next i 'rst.Close ThisDrawing.Application.Update End Sub
这个代码应该符合你的要求 |