VB实现ACCESS数据库记录的查询,新增,删除,修改
数据是用adodc加DataGrid连接ACCESS数据库,想在窗体中实现新增,查询,修改,保存,删除按钮,不知道些具体的代码有类似代码和程序的告诉我下...
数据是用adodc加DataGrid连接ACCESS数据库,想在窗体中实现新增,查询,修改,保存,删除按钮,不知道些具体的代码
有类似代码和程序的告诉我下 展开
有类似代码和程序的告诉我下 展开
3个回答
推荐于2018-05-17
展开全部
“修改”按钮的程序
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
2013-08-09
展开全部
新增:adodc1.addnew
查询:用select <字段名表> form <数据表名称或视图名称>[where<条件表达式>][group by<字段名1>][order by<字段名2>]
修改:先打开数据表然后更新表,更新:adodc1.undatecontrols
保存:adodc1.updatebatch
删除:adodc1.delete
查询:用select <字段名表> form <数据表名称或视图名称>[where<条件表达式>][group by<字段名1>][order by<字段名2>]
修改:先打开数据表然后更新表,更新:adodc1.undatecontrols
保存:adodc1.updatebatch
删除:adodc1.delete
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-08-09
展开全部
+我qq.明天给告诉你怎么加.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询