1、致命错误:实时错误’3251‘当前记录集不支持书签。这个错误会直接导致多个窗体不能运行:修改学籍信息、修改班级信息、修改课程信息、修改成绩信息均不可运行。
错误原因:模块中的adOpenKeyset 错误的写成了asOpenKeyset .键集游标(AdOpenKeyset)记录集的读写属性为“读写”,其行为类似动态游标,不同的是AdOpenKeyset将无法查看到其他用户对数据的更改。 adLockOptimistic锁定最佳区域 :当数据源正在更新时,系统并不会锁住其他用户的动作,其他用户可以对数据进行增、删、改的操作。
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
'executes SQL and returns Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim sTokens() As String
On Error GoTo ExecuteSQL_Error
sTokens = Split(SQL)
Set cnn = New ADODB.Connection
cnn.Open ConnectString
If InStr("INSERT,DELETE,UPDATE", UCase$(sTokens(0))) Then '非Select语句
cnn.Execute SQL '数据量不大时,可以在连接上,直接执行SQL语句
MsgString = sTokens(0) & " query successful"
'虽然MsgString不是返回值,但传递方式是ByRef,实参地址和这个地址相同
Else 'Select语句
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
'得到临时表,游标指向第一条记录
'get RecordCount,
Set ExecuteSQL = rst
MsgString = "查询到" & rst.RecordCount & _
" 条记录 "
End If
ExecuteSQL_Exit:
Set rst = Nothing
Set cnn = Nothing
Exit Function
ExecuteSQL_Error:
MsgString = "查询错误: " & _
Err.Description
Resume ExecuteSQL_Exit
End Function
2、实时错误‘30009’
With myflexgrid
.Rows = 2 ’讲Rows写成了Row就会出现这个错误
.CellAlignment = 4
.TextMatrix(1, 0) = "考试编号"
.TextMatrix(1, 1) = "学号"
.TextMatrix(1, 2) = "姓名"
.TextMatrix(1, 3) = "班号"
.TextMatrix(1, 4) = "课程名称"
.TextMatrix(1, 5) = "分数"
Do While Not mrc.EOF
.Rows = .Rows + 1
.CellAlignment = 4
.TextMatrix(.Rows - 1, 0) = mrc.Fields(0)
.TextMatrix(.Rows - 1, 1) = mrc.Fields(1)
.TextMatrix(.Rows - 1, 2) = mrc.Fields(2)
.TextMatrix(.Rows - 1, 3) = mrc.Fields(3)
.TextMatrix(.Rows - 1, 4) = mrc.Fields(4)
.TextMatrix(.Rows - 1, 5) = mrc.Fields(5)
mrc.MoveNext
Loop
End With
3、所有的查询窗体都有一个共同的错误。例如:查询学籍信息、查询成绩信息,都有“91错误”。
Private Sub cmdInquire_Click()
Dim txtSQL As String
Dim MsgText As String
Dim dd(4) As Boolean
Dim mrc As ADODB.Recordset
txtSQL = "select * from result_Info where " 正确的就是where后必须有个空格再加引号。