VB中怎么对数据库进行添加删除修改的操作
1个回答
展开全部
", vbOKCancel, "删除提示信息")
If c = vbOK Then
Adodc1.Recordset.Delete
Adodc1.RecordSource = "select * from 人员表"
Adodc1.RefreshEnd IfElseMsgBox "当前数据库中没有可删除的数据记录", vbOKOnly, "提示信息"End IfEnd SubPrivate Sub Command3_Click()
If Text1(0).Text = "" Or Text1(1).Text = "" Then
MsgBox "请选择需要改动的记录信息!", vbOKOnly, "错误提示"Elsec = MsgBox("确定要修改该记录吗?", vbOKCancel, "提示信息")
If c = vbOK Then '如果确认修改的话进行修改操作
If Text1(1).Text = "" Then
MsgBox "姓名不能为空值!", 48, "修改****"Else'连接所要修改的数据库
con.Open "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
'开始修改数据库
con.Execute ("UPDATE " & s1 & " SET 姓名='" & Text1(1).Text & "',年龄=" & Text1(2).Text & ",学历='" & Text1(3).Text & "',年级=" & Text1(4).Text & ", 入学时间='" & Text1(5).Text & "' where 编号='" & Trim(Text1(0)) & "'")
MsgBox "信息修改成功", 64, "修改****"con.CloseAdodc1.RecordSource = "select * from 人员表"
Adodc1.RefreshEnd IfEnd IfEnd IfEnd SubPrivate Sub Command4_Click()
Adodc1.RecordSource = "select * from 人员表 where 编号='" + Text1(0).Text + "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "该信息已存在,信息保存不成功", 64, "保存****"Elsecc = MsgBox("您确定要保存该信息吗?", 33, "信息保存提示")
If c = vbOK Then
Adodc1.Recordset.Delete
Adodc1.RecordSource = "select * from 人员表"
Adodc1.RefreshEnd IfElseMsgBox "当前数据库中没有可删除的数据记录", vbOKOnly, "提示信息"End IfEnd SubPrivate Sub Command3_Click()
If Text1(0).Text = "" Or Text1(1).Text = "" Then
MsgBox "请选择需要改动的记录信息!", vbOKOnly, "错误提示"Elsec = MsgBox("确定要修改该记录吗?", vbOKCancel, "提示信息")
If c = vbOK Then '如果确认修改的话进行修改操作
If Text1(1).Text = "" Then
MsgBox "姓名不能为空值!", 48, "修改****"Else'连接所要修改的数据库
con.Open "Provider=SQLOLEDB.1;Password=2752;Persist Security Info=True;User ID=sa;Initial Catalog=sample;Data Source=JAMLEEPC"
'开始修改数据库
con.Execute ("UPDATE " & s1 & " SET 姓名='" & Text1(1).Text & "',年龄=" & Text1(2).Text & ",学历='" & Text1(3).Text & "',年级=" & Text1(4).Text & ", 入学时间='" & Text1(5).Text & "' where 编号='" & Trim(Text1(0)) & "'")
MsgBox "信息修改成功", 64, "修改****"con.CloseAdodc1.RecordSource = "select * from 人员表"
Adodc1.RefreshEnd IfEnd IfEnd IfEnd SubPrivate Sub Command4_Click()
Adodc1.RecordSource = "select * from 人员表 where 编号='" + Text1(0).Text + "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
MsgBox "该信息已存在,信息保存不成功", 64, "保存****"Elsecc = MsgBox("您确定要保存该信息吗?", 33, "信息保存提示")
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询