vb数据库增,删,改,查简单实现

vb数据库增,删,改,查简单实现,第1张

概述Dim Con As New ADODB.Connection '定义数据库连接对象 Dim Rs As New ADODB.Recordset   '定义数据库记录集对象 Private Sub Cmd_Delete_Click() '删除一条记录     Rs.Delete     If Not Rs.BOF Then         Rs.MoveNext     Else        

Dim Con As New ADODB.Connection '定义数据库连接对象
Dim Rs As New ADODB.Recordset '定义数据库记录集对象

Private Sub Cmd_Delete_Click() '删除一条记录
Rs.Delete
If Not Rs.BOF Then
Rs.MoveNext
Else
Rs.MovePrevIoUs
End If
Call ShowInfo
End Sub

Private Sub Cmd_Exit_Click() '退出程序,关闭记录集对象Rs,关闭连接对象Con
Rs.Close
Con.Close
End
End Sub

Private Sub Cmd_Find_Click() '查询产品信息
Dim Str As String
Dim pname As String
pname = Text_PN.Text
If Text_PN.Text <> "" And Text_PriceDown.Text = "" And Text_PriceUp.Text = "" Then
Str = "Select * from producted Where pname='" & pname & "'"
ElseIf Text_PN.Text = "" And Text_PriceDown.Text <> "" And Text_PriceUp.Text <> "" Then
Str = "Select * from producted Where pPrice between '" & Val(Text_PriceDown.Text) & "' and '" & Val(Text_PriceUp.Text) & "'"
Else
Str = "Select * from producted Where pname= '" & pname & "' and pPrice between '" & Val(Text_PriceDown.Text) & "' and '" & Val(Text_PriceUp.Text) & "'"
End If
With Rs
If Rs.State = adStateOpen Then
Rs.Close
Rs.Open Str,Con,adOpenDynamic,adLock@R_902_3270@
End If
ListShow.Clear
ListShow.AddItem "产品ID " & "产品名称 " & "产品价格 " & "产品生产日期"
do while Not Rs.EOF
ListShow.AddItem Rs.FIElds(0) & " " & Rs.FIElds(1) & " " & Rs.FIElds(2) & " " & Rs.FIElds(3)
Rs.MoveNext
Loop
End With
End Sub

Private Sub Cmd_First_Click() '第一条信息
Rs.MoveFirst
Call ShowInfo
End Sub

Private Sub Cmd_Insert_Click() '增加产品
Rs.AddNew
Text_PID.Text = ""
Text_Pname.Text = ""
Text_PPrice.Text = ""
Text_PDate.Text = ""
Call ShowInfo
End Sub

Private Sub Cmd_Last_Click() '最后一条信息
Rs.MoveLast
Call ShowInfo
End Sub

Private Sub Cmd_Next_Click() '下一条信息
If Not Rs.EOF Then
Rs.MoveNext
Call ShowInfo
End If
End Sub

Private Sub Cmd_Prev_Click() '前一条信息
If Not Rs.BOF Then
Rs.MovePrevIoUs
Call ShowInfo
End If
End Sub

Private Sub Cmd_Update_Click() '更新产品信息
If Not Rs.BOF And Not Rs.EOF Then
Rs.FIElds(0) = Text_PID.Text
Rs.FIElds(1) = Text_Pname.Text
Rs.FIElds(2) = Text_PPrice.Text
Rs.FIElds(3) = Text_PDate.Text
End If
End Sub

Private Sub Form_Load() Con.ConnectionString = "ProvIDer=sqlolEDB;Persist Security Info=False;User ID=sa;PWD=密码;Initial Catalog=产品;Data Source=服务器名" '连接数据库字符串 Con.Open Con.CommandTimeout = 20 Rs.Open "producted",adLock@R_902_3270@ Call ShowInfo ListShow.AddItem "产品ID " & "产品名称 " & "产品价格 " & "产品生产日期" do while Not Rs.EOF ListShow.AddItem Rs.FIElds(0) & " " & Rs.FIElds(1) & " " & Rs.FIElds(2) & " " & Rs.FIElds(3) Rs.MoveNext Loop End Sub Private Sub ShowInfo() '显示产品信息 If Not Rs.BOF And Not Rs.EOF Then Text_PID.Text = Rs.FIElds(0) Text_Pname.Text = Rs.FIElds(1) Text_PPrice.Text = Str(Rs.FIElds(2)) Text_PDate.Text = Rs.FIElds(3) End If End Sub

总结

以上是内存溢出为你收集整理的vb数据库增,删,改,查简单实现全部内容,希望文章能够帮你解决vb数据库增,删,改,查简单实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1280613.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存