VB用 ADO数据对象保存串口处理的数据到数据库出错
模块一部分代码:
Public conn As New ADODB.Connection
Public rs1 As New ADODB.Recordset '报警故障表
Public rs2 As New ADODB.Recordset '实时显示表
Public rs3 As New ADODB.Recordset '历史数据表
Public rs4 As New ADODB.Recordset '数据采集表
Public rs5 As New ADODB.Recordset '数据显示表
Public rs6 As New ADODB.Recordset '设置信息表
Sub main()
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\数据采集.mdb;persist security info =false"
conn.Open connstr
conn.CursorLocation = adUseClient
If rs1.State = 1 Then rs1.Close
If rs2.State = 1 Then rs2.Close
If rs3.State = 1 Then rs3.Close
If rs4.State = 1 Then rs4.Close
If rs5.State = 1 Then rs5.Close
If rs6.State = 1 Then rs6.Close
Form2.Show '登陆界面
End Sub
form1的form_load部分代码:
'初始化报警显示表
rs1.Open "select* from 报警故障表", conn, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = rs1
'初始化实时显示表
rs2.Open "select* from 实时显示表", conn, adOpenKeyset, adLockOptimistic
Set DataGrid2.DataSource = rs2
'初始化历史数据表
rs3.Open "select* from 历史数据表", conn, adOpenKeyset, adLockOptimistic
Set DataGrid3.DataSource = rs3
执行oncomm函数中的call DataSave 出错 ,我点击调试按钮错误显示在这一行(注意:下面保存数据的表是数据采集表)
求原因????
[解决办法]
adOpenKeyset, adLockOptimistic
这两参数不知道多少我写的时候要保存一般写成1,2
[解决办法]
绑定了 DataGrid 就应该通过控件操作数据。
多头操作容易冲突。