VB实现ACCESS数据库记录的查询,新增,删除,修改的代码是什么?
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询