VB实现ACCESS数据库记录的查询,新增,删除,修改的代码是什么?

 我来答
猫事蕊7925
2018-02-04 · TA获得超过148万个赞
知道顶级答主
回答量:61.5万
采纳率:46%
帮助的人:3.1亿
展开全部
“修改”按钮的程序
Private Sub cmdEdit_Click()
sql = "select * from 停时统计 where date = cdate('" & Text8.Text & "') and ycqk = '" & Combo1.Text & "'and id = '" & DataGrid1.Columns(2).CellText(DataGrid1.Bookmark) & "'"
rs.Open sql, dm, adOpenDynamic, adLockOptimistic
rs.Fields("id") = Text7.Text
rs.Fields("ycqk") = Combo1.Text
rs.Fields("date1") = Text1.Text
rs.Fields("time1") = Text2.Text
rs.Fields("date2") = Text3.Text
rs.Fields("time2") = Text4.Text
rs.Update
rs.Close
End Sub

'“删除”按钮的程序
Private Sub cmdDelete_Click()
strFCode = DataGrid1.Columns(0).CellText(DataGrid1.Bookmark)
strSCode = DataGrid1.Columns(2).CellText(DataGrid1.Bookmark)
strCCode = DataGrid1.Columns(1).CellText(DataGrid1.Bookmark)
sql = "select * from 停时统计 where date='" & strFCode & "' and id='" & strSCode & "' and ycqk='" & strCCode & "'"
rs.Open sql, dm, adOpenDynamic, adLockOptimistic
rs.Delete
rs.Update
rs.Close
End Sub

'“增加”按钮的程序
Private Sub Command1_Click()
sql = "select * from 停时统计 order by id"
rs.Open sql, dm, adOpenDynamic, adLockOptimistic
rs.AddNew
rs.Fields("date") = Date
rs.Fields("id") = Text7.Text - 1
rs.Fields("ycqk") = Combo1.Text
rs.Fields("date1") = Text1.Text
rs.Fields("time1") = Text2.Text
rs.Fields("date2") = Text3.Text
rs.Fields("time2") = Text4.Text
rs.Update
rs.Close

With Adodc1
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from 停时统计 where date = cdate('" & Text8.Text & "') and ycqk = '" & Combo1.Text & "' order by id"
Adodc1.Refresh
DataGrid1.Refresh
End With
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式