laoxie_198 发表于 2008-4-22 07:06:00

[讨论]怎样提高VB+SQL数据处理速度

<p>我用VB将CAD图形中的图元信息写入到SQL中,当数据量大的时候感觉特慢,请问有什么方法优化吗?下面是我的代码:</p><p><br/>Option Explicit</p><p>Dim acadApp As AcadApplication&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p>Dim acadDoc As AcadDocument&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p>'Dim acaddoc As AcadModelSpace<br/>Const LB_ITEMFROMPOINT = &amp;H1A9</p><p>Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (ByVal hWnd As Long, ByVal wMsg As Long, _<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ByVal wParam As Long, lParam As Any) As Long<br/>Private Sub Command1_Click()<br/>'On Error Resume Next<br/><br/>&nbsp;&nbsp;&nbsp; Set acadApp = GetObject(, "AutoCAD.Application.16")<br/>&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "AUTOCAD图形软件未打开!"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' 创建一个新的AutoCAD应用程序对象<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set acadApp = CreateObject("AutoCAD.Application.16")<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox Err.Description<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ' 显示AutoCAD应用程序<br/>&nbsp;&nbsp;&nbsp; acadApp.Visible = True<br/>&nbsp;&nbsp;&nbsp; Set acadDoc = acadApp.ActiveDocument<br/>&nbsp;&nbsp;&nbsp; Dim cn As New ADODB.Connection<br/>&nbsp;&nbsp;&nbsp; acadDoc.SendCommand "zoom" &amp; vbCr &amp; "e" &amp; vbCr</p><p>Frame1.Visible = False<br/>Frame2.Visible = False<br/>Command1.Visible = False<br/>Command2.Visible = False<br/>Line2.Visible = False<br/>Line3.Visible = False<br/>Line1.Visible = False<br/>&nbsp;Dim gdp As New ADODB.Recordset<br/>&nbsp;Dim gdpp As New ADODB.Recordset<br/>&nbsp;Dim gdeo As New ADODB.Recordset<br/>&nbsp;Dim gdpv As New ADODB.Recordset<br/>&nbsp;Dim gdv33 As New ADODB.Recordset<br/>&nbsp;Dim gdv3 As New ADODB.Recordset<br/>&nbsp;Dim gdlp As New ADODB.Recordset<br/>&nbsp;Dim gg01 As New ADODB.Recordset<br/>&nbsp;Dim gg03 As New ADODB.Recordset<br/>&nbsp;Dim tdsyz As String, tdzl As String, qsxz As String, sjyt As String<br/>&nbsp;Dim sqllj As String, gdv3lj As String, gg01lj As String, gg03lj As String, gdplj As String<br/>&nbsp;Dim gdlplj, gdpvlj As String<br/>&nbsp;Dim ftype(0 To 2) As Integer<br/>&nbsp;Dim fdata(0 To 2) As Variant<br/>&nbsp;Dim gdsx As Variant<br/>&nbsp;Dim maxvid, maxvidd As Long, vid As Long, eoid As Long, pid As Long<br/>&nbsp;Dim maxga01 As String, newga01 As String<br/>&nbsp;Dim maxpid As Long, newpid As Long, maxvn As Long, newvn As Long<br/>&nbsp;Dim zdpx(), zdpxgd(), t() As Variant '宗地排序数组<br/>&nbsp;Dim jfmj As Double '街坊面积<br/>&nbsp;Dim ltime As String<br/>&nbsp;Dim djh, zdh, jfh As String<br/>&nbsp;Dim zds As Integer '宗地数<br/>&nbsp;sjyt = Trim(Text7.Text)<br/>&nbsp;tdsyz = Trim(Text6.Text)<br/>&nbsp;qsxz = Trim(Text8.Text)<br/>&nbsp;<br/>&nbsp;ltime = Date + Time<br/>&nbsp;ftype(0) = 0: fdata(0) = "LWPOLYLINE"<br/>&nbsp;ftype(1) = 8: fdata(1) = "界址线"<br/>&nbsp;ftype(2) = 70: fdata(2) = 1<br/>&nbsp;'ftype(2) = 70: fdata(2) = 1<br/>&nbsp;Dim ddzb() As Double '顶点坐标<br/>&nbsp;Dim dds, mode, jzds As Integer<br/>&nbsp;Dim zb As Variant<br/>&nbsp;Dim i As Integer<br/>&nbsp;sqllj = "provider=sqloledb.1;password=" &amp; Text4.Text &amp; " ;persist security info=true;user id=" &amp; Trim(Text3.Text) &amp; ";initial catalog=" &amp; Text2.Text &amp; " ;data source=" &amp; Text1.Text &amp; ""<br/>&nbsp;cn.Open sqllj<br/>&nbsp;jfh = Trim(Text5.Text)<br/>&nbsp;&nbsp; gdv3lj = "select maxvid=max(vid) from gdv3"<br/>&nbsp; gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/>&nbsp; Do While Not gdv3.EOF<br/>&nbsp;&nbsp;&nbsp; maxvid = gdv3.Fields("maxvid")<br/>&nbsp;&nbsp;&nbsp; gdv3.MoveNext<br/>&nbsp; Loop<br/>gdv3.Close</p><p>gdplj = "select maxpid=max(pid), js=count(pid) from gdp"<br/>gdp.Open gdplj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/>If Not gdp.EOF Then<br/>If gdp.Fields("js") &gt; 0 Then<br/>&nbsp;maxpid = gdp.Fields("maxpid")<br/>&nbsp;Else<br/>&nbsp;maxpid = 0<br/>&nbsp;End If<br/>End If<br/>gdp.Close</p><p>&nbsp;gg01.Open "select maxga01=max(ga01)from gg01 where ga01 like '200%'", cn, adOpenForwardOnly, adLockBatchOptimistic<br/>&nbsp;If Not gg01.EOF Then<br/>&nbsp;&nbsp; 'If gg01.Fields("maxga01") &lt;&gt; Null Then<br/>&nbsp;&nbsp;&nbsp; maxga01 = gg01.Fields("maxga01")<br/>&nbsp; ' Else<br/>&nbsp; ' maxga01 = "2007320506100000"<br/>&nbsp; ' End If<br/>&nbsp;&nbsp; <br/>&nbsp;End If<br/>&nbsp; gg01.Close<br/>&nbsp; <br/>&nbsp;&nbsp; newga01 = pdga01(maxga01)<br/>&nbsp; gdeo.Open "select * from gdeo where description like&nbsp; " &amp; jfh &amp; " ", cn, adOpenForwardOnly, adLockBatchOptimistic<br/>&nbsp;If Not gdeo.EOF Then<br/>&nbsp;&nbsp;&nbsp; eoid = gdeo.Fields("eoid")<br/>&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp; MsgBox "数据库中没有本街坊信息、请查实!“"<br/>&nbsp;&nbsp;&nbsp; End<br/>&nbsp; End If<br/>&nbsp;gdeo.Close</p><p>&nbsp;&nbsp; gdv3lj = "select maxvn=max(vn) , js =count(vn)from gdv3 where eoid=" &amp; eoid &amp; " and vt='100' and vid in (select pvid from gdpv where pid in (select lpid from&nbsp; gdlp where isvirtual=0))"</p><p>&nbsp; gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/>&nbsp; If Not gdv3.EOF Then<br/>&nbsp;&nbsp; If gdv3.Fields("js") &gt; 0 Then<br/>&nbsp;&nbsp;&nbsp; maxvn = gdv3.Fields("maxvn")<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp; 'gdv3.MoveNext<br/>&nbsp; End If<br/>gdv3.Close</p><p>&nbsp;i = 0<br/>On Error Resume Next<br/>&nbsp;&nbsp; Dim xzj As AcadSelectionSet<br/>&nbsp;&nbsp; If Not IsNull(acadDoc.SelectionSets.Item("st")) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set xzj = acadDoc.SelectionSets.Item("st")<br/>&nbsp;&nbsp;&nbsp;&nbsp; xzj.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp; Set xzj = acadDoc.SelectionSets.Add("st") '新建选择集<br/>&nbsp; 'MsgBox xzj.Name<br/>&nbsp; xzj.Select acSelectionSetAll, , , ftype, fdata '选择宗地<br/>&nbsp; ReDim zdpxgd(xzj.count - 1, 3)<br/>&nbsp; 'ReDim zdpxgd(xzj.Count - 1, 1)<br/>&nbsp; ReDim t(xzj.count - 1, 3)<br/>&nbsp; If xzj.count = 0 Then<br/>&nbsp;&nbsp; MsgBox "没有界址线!"<br/>&nbsp;&nbsp; End<br/>&nbsp;Else<br/>&nbsp; Dim ty As AcadEntity<br/>&nbsp; For Each ty In xzj<br/>&nbsp;&nbsp; If ty.Close = True Then<br/>&nbsp; dds = (UBound(ty.Coordinates) + 1) / 2<br/>&nbsp; zb = ty.Coordinates<br/>&nbsp; jfmj = ty.Area<br/>&nbsp;&nbsp;&nbsp; ReDim ddzb(dds * 3 - 1)<br/>&nbsp;&nbsp;&nbsp; ReDim sjzb(dds - 1, 1)<br/>&nbsp;&nbsp;&nbsp; For i = 0 To dds - 1<br/>&nbsp;&nbsp;&nbsp; 'MsgBox ty.Coordinates(2 * i)<br/>&nbsp;&nbsp;&nbsp; ddzb(3 * i) = zb(2 * i)<br/>&nbsp;&nbsp;&nbsp; ddzb(3 * i + 1) = zb(2 * i + 1)<br/>&nbsp;&nbsp;&nbsp; ddzb(3 * i + 2) = 0<br/>&nbsp;&nbsp;&nbsp; sjzb(i, 0) = zb(2 * i)<br/>&nbsp;&nbsp;&nbsp; sjzb(i, 1) = zb(2 * i + 1)<br/>&nbsp;&nbsp;&nbsp; Next i<br/>gdsx = tqjfh(ddzb)<br/>zdh = gdsx(0)<br/>tdzl = gdsx(1)<br/>&nbsp;If zdh &lt;&gt; "" Then<br/>&nbsp;jfh = Trim(Text5.Text)<br/>&nbsp;djh = jfh + zdh<br/>&nbsp;'newpid = maxpid + 1<br/>zdpxgd(zds, 0) = zdh<br/>zdpxgd(zds, 1) = ddzb<br/>zdpxgd(zds, 2) = jfmj<br/>zdpxgd(zds, 3) = tdzl<br/>zds = zds + 1<br/>End If<br/>Else<br/>&nbsp;MsgBox "本宗地界址线没有封闭!请检查!"<br/>&nbsp;End If<br/>&nbsp; Next<br/>&nbsp; End If<br/>&nbsp; '以上提取宗地号和宗地界址线坐标表。<br/>&nbsp; '以下对宗地号由大到小排序。<br/>&nbsp; Dim sd, sdd, j, ii As Integer<br/>For i = 1 To zds - 1<br/>&nbsp; For j = i - 1 To zds - 1<br/>&nbsp;&nbsp; sd = Val(zdpxgd(i - 1, 0))<br/>&nbsp;&nbsp; sdd = Val(zdpxgd(j, 0))<br/>&nbsp; If sd &gt; sdd Then<br/>&nbsp;&nbsp;&nbsp; t(i, 0) = zdpxgd(i - 1, 0)<br/>&nbsp;&nbsp;&nbsp; t(i, 1) = zdpxgd(i - 1, 1)<br/>&nbsp;&nbsp;&nbsp; t(i, 2) = zdpxgd(i - 1, 2)<br/>&nbsp;&nbsp;&nbsp; t(i, 3) = zdpxgd(i - 1, 3)<br/>&nbsp;&nbsp;&nbsp; zdpxgd(i - 1, 0) = zdpxgd(j, 0)<br/>&nbsp;&nbsp;&nbsp; zdpxgd(i - 1, 1) = zdpxgd(j, 1)<br/>&nbsp;&nbsp;&nbsp; zdpxgd(i - 1, 2) = zdpxgd(j, 2)<br/>&nbsp;&nbsp;&nbsp; zdpxgd(i - 1, 3) = zdpxgd(j, 3)<br/>&nbsp;&nbsp;&nbsp; zdpxgd(j, 0) = t(i, 0)<br/>&nbsp;&nbsp;&nbsp; zdpxgd(j, 1) = t(i, 1)<br/>&nbsp;&nbsp;&nbsp; zdpxgd(j, 2) = t(i, 2)<br/>&nbsp;&nbsp;&nbsp; zdpxgd(j, 3) = t(i, 3)<br/>&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;Next j<br/>&nbsp;Next i<br/>&nbsp; '宗地号由小到大排序完毕。<br/>&nbsp;' newga01 = pdga01(maxga01)<br/>&nbsp;'新增宗地数据开始上传<br/>Bar1.Top = 1300<br/>&nbsp; Bar1.Width = 2500<br/>&nbsp; Bar1.Left = 1000<br/>&nbsp; Bar1.Min = 0<br/>&nbsp; Bar1.Max = zds<br/>&nbsp;For ii = 0 To zds - 1<br/>&nbsp; 'newpid = maxpid + 1<br/>Bar1.Value = ii<br/>&nbsp; <br/>&nbsp; djh = jfh + zdpxgd(ii, 0)<br/>&nbsp; gdplj = "select * from gdp where pid in (select ga33 from gg01 where ga18 = '" &amp; djh &amp; "' )"<br/>&nbsp; gdp.Open gdplj, cn, adOpenDynamic, adLockPessimistic<br/>&nbsp; If gdp.EOF Then<br/>&nbsp; 'cn.Execute "set identity_insert gdp on"<br/>&nbsp; 'cn.Execute "insert into gdp&nbsp; values( " &amp; newpid &amp; ", '100' ,'" &amp; zdpxgd(ii, 0) &amp; " '," &amp; eoid &amp; " ,0,0,0,0.0,0.0,0,0.0, 0,'" &amp; ltime &amp; " '," &amp; zdpxgd(ii, 2) &amp; ",1)"<br/>&nbsp; cn.Execute "insert into gdp&nbsp; values( '100' ,'" &amp; zdpxgd(ii, 0) &amp; " '," &amp; eoid &amp; " ,0,0,0,0.0,0.0,0,0.0, 0,'" &amp; ltime &amp; " '," &amp; zdpxgd(ii, 2) &amp; ",1)"<br/>&nbsp; gdpp.Open "select maxpid=max(pid) from gdp ", cn, adOpenDynamic, adLockPessimistic<br/>&nbsp; If Not gdpp.EOF Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; newpid = gdpp.Fields("maxpid")<br/>&nbsp; End If<br/>&nbsp; gdpp.Close<br/>&nbsp; cn.Execute "insert into gdlp values(" &amp; newpid &amp; ",'" &amp; sjyt &amp; "','" &amp; tdsyz &amp; "','" &amp; newga01 &amp; "',1,0,0.0,0.0,1)"<br/>&nbsp; 'cn.Execute "insert into gg01 values( '" &amp; newga01 &amp; " ','0','','','" &amp; Left(djh, 6) &amp; " ','" &amp; Mid(djh, 7, 3) &amp; " ','" &amp; Mid(djh, 10, 3) &amp; " ','" &amp; zdh &amp; " ','" &amp; ltime &amp; " ','002','','','','','','','','','','','','" &amp; djh &amp; " ',' ',' ',' ','0','0',' ',' ',' ',' ','Y',0,0,'',0," &amp; maxpid + 1 &amp; ",' Y ',0,0,0,'" &amp; jmj &amp; "',0,'','0',0)"<br/>&nbsp; gg01.Open "select * from gg01", cn, adOpenDynamic, adLockPessimistic<br/>&nbsp;' If gg01 Then<br/>&nbsp;&nbsp; gg01.AddNew<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga01") = newga01<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga02") = "0"<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga03") = tdsyz<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga031") = Left(djh, 6)<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga032") = Mid(djh, 7, 3)<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga033") = Mid(djh, 10, 3)<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga034") = zdpxgd(ii, 0)<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga04") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga05") = ltime<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga051") = "002"<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga06") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga07") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga08") = zdpxgd(ii, 3)<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga09") = ""<br/>&nbsp;&nbsp;&nbsp; 'gg01.Fields("ga10") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga11") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga12") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga13") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga14") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga15") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga16") = "1"<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga17") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga18") = Left(djh, 6) + Mid(djh, 7, 3) + Mid(djh, 10, 3) + zdpxgd(ii, 0)<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga19") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga21") = Null<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga22") = Null<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga23") = 0<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga24") = Val(sjyt)<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga25") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga251") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga26") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga27") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga28") = "Y"<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga29") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga30") = 0<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga31") = ""<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga32") = "N"<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga33") = newpid<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga34") = "Y"<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga35") = Null<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga36") = Null<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga37") = Null<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga221") = zdpxgd(ii, 2)<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga222") = Null<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga38") = Null<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga39") = Null<br/>&nbsp;&nbsp;&nbsp; gg01.Fields("ga381") = Null<br/>&nbsp;&nbsp; gg01.Update<br/>&nbsp;&nbsp; gg01.MoveNext<br/>&nbsp; 'End If<br/>&nbsp;&nbsp; <br/>&nbsp; gg01.Close<br/>&nbsp; <br/>&nbsp; zb = zdpxgd(ii, 1)<br/>&nbsp;jzds = (pdws(zb) + 1) / 3<br/>&nbsp; For i = 0 To jzds - 1<br/>&nbsp;' For i = 0 To zdpxgd(ii, 1).cone<br/>&nbsp; gdv3lj = "select * from gdv3 where x=" &amp; zb(3 * i + 1) &amp; " and y= " &amp; zb(3 * i) &amp; " and vt=100"<br/>&nbsp; gdv3.Open gdv3lj, cn, adOpenForwardOnly, adLockBatchOptimistic<br/>&nbsp; <br/>&nbsp; If Not gdv3.EOF Then<br/>&nbsp;&nbsp;&nbsp; vid = gdv3.Fields("vid")<br/>&nbsp;&nbsp;&nbsp; newvn = gdv3.Fields("vn")<br/>&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp; vid = maxvid + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp; newvn = maxvn + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp; maxvn = maxvn + 1<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Execute "set identity_insert gdv3 on"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cn.Execute "insert into gdv3&nbsp; values ( " &amp; eoid &amp; ",' " &amp; newvn &amp; "'," &amp; zb(3 * i + 1) &amp; "," &amp; zb(3 * i) &amp; ",0,2,1,1,0,'" &amp; ltime &amp; "',100)"<br/>&nbsp; End If<br/>&nbsp;&nbsp; gdv33.Open "select maxvid=max(vid) from gdv3 ", cn, adOpenForwardOnly, adLockBatchOptimistic<br/>&nbsp;&nbsp; If Not gdv33.EOF Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; maxvidd = gdv33.Fields("maxvid")<br/>&nbsp;&nbsp;&nbsp;&nbsp; If maxvidd &gt; maxvid Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; vid = maxvidd<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp; maxvid = maxvidd<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp; gdv33.Close<br/>&nbsp;&nbsp; <br/>&nbsp;&nbsp; ' cn.Execute "set identity_insert gdeov on"<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; cn.Execute "insert into gdpv&nbsp; values (" &amp; newpid &amp; "," &amp; i + 1 &amp; "," &amp; vid &amp; ")"<br/>&nbsp;&nbsp;&nbsp; cn.Execute "insert into gg03 values (" &amp; newga01 &amp; "," &amp; i + 1 &amp; "," &amp; i + 1 &amp; " ," &amp; newvn &amp; ",null,4,null,null,2,3,null)"<br/>&nbsp; ' maxvid = maxvid + 1<br/>&nbsp;&nbsp; 'maxvn = maxvn + 1<br/>&nbsp; gdv3.Close<br/>&nbsp; Next<br/>&nbsp; <br/>&nbsp; maxpid = maxpid + 1<br/>&nbsp; newga01 = pdga01(newga01)<br/>&nbsp;&nbsp; 'MsgBox ty.ObjectName</p><p>&nbsp;&nbsp; End If 'If gdp.EOF Then<br/>&nbsp;&nbsp; gdp.Close<br/>&nbsp; Next<br/>&nbsp; MsgBox "数据上传完毕!"<br/>&nbsp; End<br/>&nbsp; End<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; <br/>End Sub</p><p>Function tqjfh(xxzb) As Variant&nbsp; '提取宗地号、土地坐落<br/>&nbsp;On Error Resume Next<br/>&nbsp;Dim jfh(0 To 1) As String<br/>&nbsp; Dim zjxzj As AcadSelectionSet<br/>&nbsp;&nbsp;&nbsp;&nbsp; If Not IsNull(acadDoc.SelectionSets.Item("zjst")) Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; Set zjxzj = acadDoc.SelectionSets.Item("zjst")<br/>&nbsp;&nbsp;&nbsp;&nbsp; zjxzj.Delete<br/>&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp; Set zjxzj = acadDoc.SelectionSets.Add("zjst") '新建选择集<br/>&nbsp; Dim ftype As Variant, fdata As Variant<br/>&nbsp; Call creatssetfilter(ftype, fdata, 0, "Text", 8, "宗地注记,土地座落")<br/>&nbsp; 'ReDim gpCode(0 To 1) As Integer<br/>&nbsp;&nbsp;&nbsp; ''gpCode(0) = 0<br/>&nbsp;&nbsp;&nbsp; ''gpCode(1) = 8<br/>&nbsp;&nbsp; '' ReDim dataValue(0 To 1) As Variant<br/>&nbsp;&nbsp;&nbsp; ''dataValue(0) = "TEXT"<br/>&nbsp;&nbsp; '' dataValue(1) = "宗地注记"<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp; '' Dim groupCode As Variant, dataCode As Variant<br/>&nbsp;&nbsp; '' groupCode = gpCode<br/>&nbsp;&nbsp; '' dataCode = dataValue<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; zjxzj.SelectByPolygon acSelectionSetWindowPolygon, xxzb, ftype, fdata<br/>&nbsp;&nbsp;&nbsp; If zjxzj.count = 0 Then<br/>&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "没有宗地号,请检查!"<br/>&nbsp;&nbsp;&nbsp; ' End<br/>&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; 'zjxzj.SelectByPolygon acSelectionSetWindowPolygon, pointsArray, groupCode, dataCode<br/>&nbsp;&nbsp;&nbsp; If zjxzj.Item(0).Layer = "宗地注记" Then<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jfh(0) = zjxzj.Item(0).TextString&nbsp; '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jfh(1) = zjxzj.Item(1).TextString<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jfh(1) = zjxzj.Item(0).TextString&nbsp; '<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jfh(0) = zjxzj.Item(1).TextString<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp; End If<br/>&nbsp; <br/>&nbsp; '以上提取街坊坐标和街坊号<br/>tqjfh = jfh<br/>zjxzj.Delete<br/>End Function<br/>Function pdga01(maxga01) As String '判断调查表号<br/>Dim hm As String<br/>hm = Val(Str$(Right(maxga01, 6)) + 1)<br/>Select Case Len(hm)<br/>&nbsp; Case 1: hm = "00000" + hm<br/>&nbsp; Case 2: hm = "0000" + hm<br/>&nbsp; Case 3: hm = "000" + hm<br/>&nbsp; Case 4: hm = "00" + hm<br/>&nbsp; Case 5: hm = "0" + hm<br/>&nbsp; End Select<br/>pdga01 = Left(maxga01, 10) + hm</p><p>End Function<br/>Function pdws(mArray As Variant) As Integer<br/>Dim i As Integer<br/>Dim Ret As Integer<br/>Dim ErrF As Boolean<br/>Dim arrayrange As Integer<br/>ErrF = False<br/>On Error GoTo ErrHandle<br/>'判断代入的参数是否为数组<br/>If Not IsArray(mArray) Then<br/>pdws = -1<br/>Exit Function<br/>End If<br/>'VB中数组最大为60<br/>For i = 1 To 60<br/>'用UBound函数判断某一维的上界,如果大数组的实际维数时产生超出范围错误,<br/>' 此时我们通过Resume Next 来捕捉错这个错误<br/>Ret = UBound(mArray, i)<br/>If ErrF Then Exit For<br/>Next i<br/>'最后返回<br/>arrayrange = Ret<br/>Exit Function<br/>ErrHandle:<br/>'Ret = i - 1<br/>'ErrF = True<br/>'Resume Next<br/>pdws = Ret<br/>End Function</p><p>Private Sub CommandButton2_Click()<br/>End<br/>End Sub</p><p></p><p><br/>Private Sub Command2_Click()<br/>End<br/>End Sub<br/>Public Sub creatssetfilter(ByRef filtertype As Variant, ByRef filterdata As Variant, ParamArray filter()) '选择集过滤器<br/>If UBound(filter) Mod 2 = 0 Then<br/>&nbsp;MsgBox "filter 参数无效"<br/>&nbsp; Exit Sub<br/>End If<br/>Dim ftype() As Integer<br/>Dim ftada() As Variant<br/>Dim count As Integer<br/>count = (UBound(filter) + 1) / 2<br/>ReDim ftype(count - 1)<br/>ReDim fdata(count - 1)<br/>Dim i As Integer<br/>For i = 0 To count - 1<br/>&nbsp; ftype(i) = filter(2 * i)<br/>&nbsp; fdata(i) = filter(2 * i + 1)<br/>&nbsp; Next i<br/>&nbsp; filtertype = ftype<br/>&nbsp; filterdata = fdata<br/>End Sub<br/></p>

idoo 发表于 2008-4-27 19:15:00

不了解,帮顶
页: [1]
查看完整版本: [讨论]怎样提高VB+SQL数据处理速度