laoxie_198 发表于 2006-11-9 16:31:00

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

<P>下面是我的语句运行时要出错!总是提醒在此上下文中不允许使用"tysx",此处只允许使用常量 ,表达式,或变量,不允许使用列名.可tysx就是变量!清高手指点</P>
<P>&nbsp;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>&nbsp;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>&nbsp;&nbsp;&nbsp; rst.Open "select * from tysx where&nbsp; cadid =" &amp; obj.ObjectID &amp; "", cn, adOpenStatic, </P>
<P>adLockReadOnly<BR>&nbsp;&nbsp;&nbsp; If Not rst.EOF Then<BR>&nbsp;&nbsp;&nbsp; id = rst.Fields("cadid")<BR>&nbsp;&nbsp;&nbsp; cadid = rst.Fields("cadid")<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp; rst.Close<BR>&nbsp;&nbsp;&nbsp; rst.Open blj, cn, adOpenDynamic, adLockBatchOptimistic<BR>&nbsp;&nbsp;&nbsp; If cadid = obj.ObjectID Then<BR>&nbsp;&nbsp;&nbsp;&nbsp; cn.Execute "update tysx set area=" &amp; obj.Area &amp; ",lasttime=" &amp; mytime &amp; " where cadid=" &amp; </P>
<P>obj.ObjectID &amp; ""<BR>&nbsp;&nbsp;&nbsp; Else<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp; 'cn.Execute "insert into tysx values (" &amp; obj.ObjectID &amp; ", 44 , " &amp; obj.Area &amp; "," &amp; obj.Area &amp; </P>
<P>")"<BR>&nbsp;&nbsp; cn.Execute "insert into tysx values (" &amp; obj.ObjectID &amp; ", tysx , " &amp; obj.Area &amp; ", " &amp; mytime &amp; </P>
<P>" )"<BR>&nbsp;&nbsp; End If<BR>&nbsp;&nbsp; rst.Close<BR>&nbsp;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>&nbsp;&nbsp; Do While Not rst.EOF<BR>&nbsp;&nbsp;&nbsp;&nbsp; js = 0<BR>&nbsp;&nbsp;&nbsp;&nbsp; For Each obj In ThisDrawing.ModelSpace<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If rst.Fields("cadid") = obj.ObjectID Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; js = js + 1<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'cn.Execute "delete tytable where id= " &amp; obj.ObjectID &amp; ""<BR>&nbsp;&nbsp;&nbsp;&nbsp; Next obj<BR>&nbsp;&nbsp;&nbsp;&nbsp; If js = 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp; cn.Execute "delete tysx where cadid=" &amp; rst.Fields("cadid") &amp; ""<BR>&nbsp;&nbsp;&nbsp;&nbsp; End If<BR>&nbsp;&nbsp;&nbsp;&nbsp; rst.MoveNext<BR>&nbsp;&nbsp; Loop<BR>rst.Close<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; <BR>End Sub</P>
<P><BR>&nbsp;</P>
页: [1]
查看完整版本: [求助]大家帮我看看我的错误出在那