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