下面是我的语句运行时要出错!总是提醒在此上下文中不允许使用"tysx",此处只允许使用常量 ,表达式,或变量,不允许使用列名.可tysx就是变量!清高手指点
Sub tylk() '图元连库 Dim cn As New ADODB.Connection Dim rst As New ADODB.Recordset Dim klj, blj As String Dim tysx As String Dim id, cadid, js As Long Dim mytime As Date Dim dds As Integer Dim plzb As Variant '顶点坐标数组 'mytime = Day(Now) + 37024 mytime = 37025
blj = "select * from tysx" klj = "provider=sqloledb.1;password=;persist security info=true;user id=sa;initial catalog=cadsql
;data source=huangbin" '库连接字符串 'klj = "Provider=MSDASQL.1ersist Security Info=False;Data Source=hbcad" cn.Open klj '连接数据库 Dim obj As AcadEntity 'rst.Open blj, cn, adOpenDynamic, adLockBatchOptimistic For Each obj In ThisDrawing.ModelSpace tysx = obj.ObjectName plzb = obj.Coordinates dds = (UBound(plzb) + 1) / 2 Dim i As Integer Dim point As Variant rst.Open "select * from tysx where cadid =" & obj.ObjectID & "", cn, adOpenStatic,
adLockReadOnly If Not rst.EOF Then id = rst.Fields("cadid") cadid = rst.Fields("cadid") End If rst.Close rst.Open blj, cn, adOpenDynamic, adLockBatchOptimistic If cadid = obj.ObjectID Then cn.Execute "update tysx set area=" & obj.Area & ",lasttime=" & mytime & " where cadid=" &
obj.ObjectID & "" Else 'cn.Execute "insert into tysx values (" & obj.ObjectID & ", 44 , " & obj.Area & "," & obj.Area &
")" cn.Execute "insert into tysx values (" & obj.ObjectID & ", tysx , " & obj.Area & ", " & mytime &
" )" End If rst.Close rst.Open blj, cn, adOpenDynamic, adLockBatchOptimistic findid rst, obj, cn Next obj
End Sub '图形中删除图元时库中也删除。 Private Sub findid(rst, obj As AcadEntity, cn) Dim js As Integer Do While Not rst.EOF js = 0 For Each obj In ThisDrawing.ModelSpace If rst.Fields("cadid") = obj.ObjectID Then js = js + 1 End If 'cn.Execute "delete tytable where id= " & obj.ObjectID & "" Next obj If js = 0 Then cn.Execute "delete tysx where cadid=" & rst.Fields("cadid") & "" End If rst.MoveNext Loop rst.Close End Sub
|