vb6.0+acess数据库编程,用adodc,用commandbutton增加一条记录怎么编程
用rsRecordSet.AddNew增加一条记录的时候,保存时,出错'3251',说不支持更新,说可能是提供程序的限制,也可能是选定锁定类型的限制.具体程序如下:Pri...
用rsRecordSet.AddNew增加一条记录的时候,保存时,出错'3251',说不支持更新,说可能是提供程序的限制,也可能是选定锁定类型的限制.具体程序如下:
Private Sub cmdSave_Click()
If cmdAdd.Caption = "取消" Then
rsRecordSet.AddNew
j = j + 1
' connconnection.Execute ("insert into course(Kcbh,Kcmc))
End If
Call WriteDataFromControls '调用函数,给相应的字段赋值
rsRecordSet.Update
mblnAddMode = False
cmdSave.Enabled = False
If cmdAdd.Caption = "取消" Then
cmdAdd.Caption = "添加"
End If
If cmdEdit.Caption = "取消" Then
cmdEdit.Caption = "修改"
End If
Call EnableNavigation
cmdEdit.Enabled = True
cmdAdd.Enabled = True
cmdDelete.Enabled = True
rsRecordSet.Close
rsRecordSet.Open
End Sub 展开
Private Sub cmdSave_Click()
If cmdAdd.Caption = "取消" Then
rsRecordSet.AddNew
j = j + 1
' connconnection.Execute ("insert into course(Kcbh,Kcmc))
End If
Call WriteDataFromControls '调用函数,给相应的字段赋值
rsRecordSet.Update
mblnAddMode = False
cmdSave.Enabled = False
If cmdAdd.Caption = "取消" Then
cmdAdd.Caption = "添加"
End If
If cmdEdit.Caption = "取消" Then
cmdEdit.Caption = "修改"
End If
Call EnableNavigation
cmdEdit.Enabled = True
cmdAdd.Enabled = True
cmdDelete.Enabled = True
rsRecordSet.Close
rsRecordSet.Open
End Sub 展开
2个回答
展开全部
在用Adodc连接数据库前 不要忘了加引用数据库引擎 microsoft Jet and ...
'连接数据库
Private Sub Form_Load()
On Error Resume Next
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\你的数据库名.mdb;Persist Security Info=False"
Dim strquery As String
strquery = "select * from 表名"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strquery
Adodc1.Refresh
Set Datagrid1.Datasource = Adodc1
End Sub
'添加记录
Private Sub Command1_Click()
On Error Resume Next
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then
MsgBox "添加的数据不能为空" & vbCrLf & " 请您重新输入", vbExclamation, "数据库添加"
Exit Sub
Else
'=====================本段为添加数据库内容(添加完自动保存)
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("列名1").Value = Text1.Text
Adodc1.Recordset.Fields("列名2").Value = Text2.Text
Adodc1.Recordset.Fields("列名3").Value = Text3.Text
Adodc1.Recordset.Fields("列名4").Value = Text4.Text
Adodc1.Recordset.Update
'================================================
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End If
End Sub
'连接数据库
Private Sub Form_Load()
On Error Resume Next
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\你的数据库名.mdb;Persist Security Info=False"
Dim strquery As String
strquery = "select * from 表名"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = strquery
Adodc1.Refresh
Set Datagrid1.Datasource = Adodc1
End Sub
'添加记录
Private Sub Command1_Click()
On Error Resume Next
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Or Text4.Text = "" Then
MsgBox "添加的数据不能为空" & vbCrLf & " 请您重新输入", vbExclamation, "数据库添加"
Exit Sub
Else
'=====================本段为添加数据库内容(添加完自动保存)
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("列名1").Value = Text1.Text
Adodc1.Recordset.Fields("列名2").Value = Text2.Text
Adodc1.Recordset.Fields("列名3").Value = Text3.Text
Adodc1.Recordset.Fields("列名4").Value = Text4.Text
Adodc1.Recordset.Update
'================================================
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询