用VB中的ADO和Datagrid控件做个Access数据库程序,要求有添加、删除、查询、修改等功能

895795776@qq.com,能不能发个给我
2024-12-29 01:43:27
推荐回答(1个)
回答1:

Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim str As String
Set conn = New ADODB.Connection
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\检测中心维修管理系统.mdb;Persist Security Info=False"
conn.Open
str = "SELECT * From 设备分类"
Set rs = New ADODB.Recordset
rs.Open str, conn, adOpenStatic, adLockReadOnly
If Not IsNull(rs.Fields("设备类别")) Then Combo2.Text = rs.Fields("设备类别")

rs.Close

If Text1.Text = "" Then
MsgBox "设备编号不能为空值!!"
Else
Adodc1.RecordSource = "select * from 设备台帐"
Adodc1.Refresh
With Adodc1.Recordset
.AddNew
.Fields("设备编号") = Text1
.Fields("设备名称") = Text2
.Fields("规格型号") = Text3
.Fields("出厂编号") = Text4
.Fields("设备类别") = Combo2
.Fields("使用单位") = Text6
.Fields("制造厂商") = Text7
.Fields("设备所在地") = Text8
mst.Type = adTypeBinary
mst.Open
If photoFilename <> "" Then mst.LoadFromFile photoFilename
.Fields("设备照片") = mst.Read
.Fields("制造日期") = DTPicker1
.Fields("使用日期") = DTPicker2
.Fields("备注") = Text9
.Update

mst.Close
Adodc1.RecordSource = "select * from 设备台帐 order by 设备编号"

.Close
MsgBox "添加设备信息成功!", 48, "提示"
End With
End If
查询
If Text1.Text = "" Then
MsgBox "设备编号不能为空", , Me.Caption
Exit Sub
End If
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\检测中心维修管理系统.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from 设备台帐 where 设备编号 like '%" & Trim(Text1.Text) & "%' "
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Text1.Text = Adodc1.Recordset.Fields("设备编号")
Text2.Text = Adodc1.Recordset.Fields("设备名称")
Text3.Text = Adodc1.Recordset.Fields("规格型号")
Text4.Text = Adodc1.Recordset.Fields("出厂编号")
Combo2.Text = Adodc1.Recordset.Fields("设备类别")
Text6.Text = Adodc1.Recordset.Fields("使用单位")
Text7.Text = Adodc1.Recordset.Fields("制造厂商")
Text8.Text = Adodc1.Recordset.Fields("设备所在地")

DTPicker1.Value = Adodc1.Recordset.Fields("制造日期")
DTPicker2.Value = Adodc1.Recordset.Fields("使用日期")
Text9.Text = Adodc1.Recordset.Fields("备注")
Else
MsgBox "没有该设备"
End If