VB+Access进行查询,修改,删除

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

“修改”按钮的程序 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




做一个小型的管理系统,要对数据库的数据进行查询,修改,删除的具体步骤是怎样的?

比如我在text里面输入姓名,按查询按钮后在text2显示这个姓名的联系电话,在text3显示这个姓名的编号.该怎样写代码啊?
问题补充:
如果有实例可以发到我邮箱吗?sslkmtg@

满意答案 好评率:100%
'假设查询、删除、修改都以姓名为条件
Dim con As New ADODB.Connection

Private Sub Command1_Click() '查询
Dim sSQL As String
Dim rs As New ADODB.Recordset

sSQL = "select 电话号码字段名称 from 数据表名称 where 姓名字段名称 = '" & Text1.Text & "'"
rs.Open sSQL, con, adOpenKeyset, adLockOptimistic

If rs.RecordCount > 0 Then
rs.MoveFirst
Text2.Text = rs!电话号码字段名称
End If
Set rs = Nothing
End Sub

Private Sub Command2_Click() '修改
Dim sSQL As String
Dim rs As New ADODB.Recordset

sSQL = "select * from 数据表名称"
rs.Open sSQL, con, adOpenKeyset, adLockOptimistic

rs!电话号码字段名称 = Text2.Text
rs.Update

Set rs = Nothing
End Sub

Private Sub Command3_Click() '删除
Dim sSQL As String
sSQL = "Delete * from 数据表名称 where 姓名字段名称 = '" & Text1.Text & "'"
con.Execute sSQL
End Sub

Private Sub Form_Load()
Call

OpenDatabase '初始化数据库连接
End Sub

Private Sub OpenDatabase()
'连接你的数据库
End Sub




相关文档
最新文档