找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 689|回复: 0

[求助]:清大家帮我看看我的错误出在那里?

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

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
下面是我的语句运行时要出错!总是提醒在此上下文中不允许使用"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.1;Persist 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
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-12-23 10:54 , Processed in 0.378511 second(s), 31 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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