为什么SQL数据库在运行时,系统会变慢???急!!!
我用VB6.0编写了一个接收数据然后存入SQL2000数据库的一个程序,在接收到上万条数据后,在拖动本系统界面时会显得很慢,请问各位高手这是怎么回事呀?下面是我编写存入数据库的那段代码,请各位高手指点!
Public Sub SaveDataBase()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
On Error GoTo handle
cn.Open "Driver={SQL Server};Server= " & SetForm.Text8.Text & "; " & "Database=Personnellocalizer;Uid=;Pwd= "
rs.Open "PersonnelOrientationInfo ", cn, adOpenKeyset, adLockOptimistic
rs.AddNew
Text1(0).Text = rs.RecordCount + 1
rs.Fields( "ID ") = rs.RecordCount
rs.Fields( "CardNumber ") = Text1(1).Text
rs.Fields( "TransceiverStationNumber ") = Text1(2).Text
rs.Fields( "DataSendTime ") = Text1(3).Text
rs.Fields( "State ") = Text1(4).Text
rs.Fields( "Remark ") = Text1(5).Text
rs.Update
'rs.MoveLast
Label5.Caption = rs.RecordCount
Counter = Counter + 1
MainInceptDataStr = Format(Now, "yyyy-MM-dd HH:mm:ss ") & " 正在接收第 " & Counter & " 条数据 "
If SetForm.Combo6.Text = "True " Then
Call InceptData
Else
Exit Sub
End If
handle:
On Error GoTo 0
End Sub
[解决办法]
增加记录:cn.execute "insert into (...) values(...) "
修改记录:cn.execute "update tablename set ... where ... "
删除记录:cn.execute "delete from tablename where ... "