无法存储到数据库,报错'3251 当前记录集不支持更新
主要代码DimLs_connAsStringDimmy_connAsADODB.ConnectionDimmy_recordsetAsADODB.RecordsetPri...
主要代码
Dim Ls_conn As String
Dim my_conn As ADODB.Connection
Dim my_recordset As ADODB.Recordset
Private Sub Getdata()
Dim Li_rowcount As Integer
Dim Li_i As Integer
If my_conn.State = adStateClosed Then my_conn.Open
my_recordset.Open "Select * From 章节", my_conn, adOpenStatic, adLockReadOnly
Li_rowcount = my_recordset.RecordCount - 1
For Li_i = 0 To Li_rowcount
ListView1.ListItems.Add , , Li_i + 1
ListView1.ListItems.Item(Li_i + 1).SubItems(1) = my_recordset.Fields(1).Value
ListView1.ListItems.Item(Li_i + 1).SubItems(2) = my_recordset.Fields(2).Value
my_recordset.MoveNext
Next
my_recordset.Close
End Sub
Private Sub Command6_Click()
If Len(Trim(Text2.Text)) = 0 Then
MsgBox "类型不能为空", vbInformation Or vbOKOnly, "系统提示"
Text2.SetFocus
Exit Sub
End If
If my_recordset.State = adStateClosed Then my_recordset.Open
my_recordset.AddNew????这里报错
my_recordset.Fields(2) = Trim(Combo1.Text)
my_recordset.Fields(3) = Trim(Text2.Text)
my_recordset.Update
ListView1.ListItems.Clear
Getdata
End Sub
Private Sub Form_Load()
Ls_conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data.mdb;Persist Security Info=False"
Text2.Text = ""
Combo1.AddItem "第一章"
Combo1.AddItem "第二章"
Combo1.AddItem "第三章"
Combo1.AddItem "第四章"
Combo1.ListIndex = 0
ListView1.ColumnHeaders.Add , , "编号"
ListView1.ColumnHeaders.Add , , "类型"
ListView1.ColumnHeaders.Add , , "章节"
ListView1.GridLines = True
ListView1.FullRowSelect = True
ListView1.LabelEdit = lvwManual
ListView1.View = lvwReport
ListView1.HideSelection = False
Set my_conn = New ADODB.Connection
Set my_recordset = New ADODB.Recordset
my_conn.ConnectionString = Ls_conn
Getdata
End Sub 展开
Dim Ls_conn As String
Dim my_conn As ADODB.Connection
Dim my_recordset As ADODB.Recordset
Private Sub Getdata()
Dim Li_rowcount As Integer
Dim Li_i As Integer
If my_conn.State = adStateClosed Then my_conn.Open
my_recordset.Open "Select * From 章节", my_conn, adOpenStatic, adLockReadOnly
Li_rowcount = my_recordset.RecordCount - 1
For Li_i = 0 To Li_rowcount
ListView1.ListItems.Add , , Li_i + 1
ListView1.ListItems.Item(Li_i + 1).SubItems(1) = my_recordset.Fields(1).Value
ListView1.ListItems.Item(Li_i + 1).SubItems(2) = my_recordset.Fields(2).Value
my_recordset.MoveNext
Next
my_recordset.Close
End Sub
Private Sub Command6_Click()
If Len(Trim(Text2.Text)) = 0 Then
MsgBox "类型不能为空", vbInformation Or vbOKOnly, "系统提示"
Text2.SetFocus
Exit Sub
End If
If my_recordset.State = adStateClosed Then my_recordset.Open
my_recordset.AddNew????这里报错
my_recordset.Fields(2) = Trim(Combo1.Text)
my_recordset.Fields(3) = Trim(Text2.Text)
my_recordset.Update
ListView1.ListItems.Clear
Getdata
End Sub
Private Sub Form_Load()
Ls_conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data.mdb;Persist Security Info=False"
Text2.Text = ""
Combo1.AddItem "第一章"
Combo1.AddItem "第二章"
Combo1.AddItem "第三章"
Combo1.AddItem "第四章"
Combo1.ListIndex = 0
ListView1.ColumnHeaders.Add , , "编号"
ListView1.ColumnHeaders.Add , , "类型"
ListView1.ColumnHeaders.Add , , "章节"
ListView1.GridLines = True
ListView1.FullRowSelect = True
ListView1.LabelEdit = lvwManual
ListView1.View = lvwReport
ListView1.HideSelection = False
Set my_conn = New ADODB.Connection
Set my_recordset = New ADODB.Recordset
my_conn.ConnectionString = Ls_conn
Getdata
End Sub 展开
1个回答
展开全部
my_recordset.Open "Select * From 章节", my_conn, adOpenStatic, adLockReadOnly
这里你指定了adOpenStatic,不支持AddNew动态更新,要用adOpenDynamic
这里你指定了adOpenStatic,不支持AddNew动态更新,要用adOpenDynamic
更多追问追答
追问
my_recordset.Open "Select * From 章节", my_conn, adOpenDynamic, adLockReadOnly
这样之前也改过,问题还是一样
追答
你是操作的表吗,如果是表,那是权限(包括这个文件的读写权)问题,如果是视图(就是MDB中的查询),那就是这个视图不支持动态更新。另外,你可以用adOpenDynamic, adLockOptimistic,配合试试
这个 From 章节 的“章节”如果是个表名,有二种情况导致不能更新
(1)你的MDB文件,当前没有写权限;
(2)存在独占打开它的进程,或你的ODBC配置中,没有用可以写的方式打开它
你可以仔细检查下上面的原因,如果“章节”不是表,则不能写是可能的,主要看你的定义
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询