明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1174|回复: 0

[求助]大家帮我看看我的错误出在那

[复制链接]
发表于 2006-11-9 16:31:00 | 显示全部楼层 |阅读模式

下面是我的语句运行时要出错!总是提醒在此上下文中不允许使用"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


 

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 20:28 , Processed in 0.162627 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表