VB创建一个应用程序,能对Access数据库文件中的数据进行增、删、改和查询操作(查询必须使用SQL语句)。

能举个实例告诉我详细点的过程吗,还有编码。。。就是具体是怎么做的。。。谢谢简单点的就行。。不用太复杂的... 能举个实例告诉我详细点的过程吗,还有编码。。。就是具体是怎么做的。。。谢谢
简单点的就行。。不用太复杂的
展开
 我来答
dear156163
2009-12-11 · TA获得超过203个赞
知道小有建树答主
回答量:108
采纳率:0%
帮助的人:153万
展开全部
我做的一个用来登记银行卡号的系统,实用简单型的,ADO链接数据库,时间也很赶,我觉得刚好合适,改了一下,LZ看看:

登记银行卡号系统.vbp:

Type=Exe
Form=登记银行卡号系统.frm
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\windows\system32\stdole2.tlb#OLE Automation
Object={F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0; comdlg32.ocx
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; mscomctl.ocx
IconForm="Form1"
Startup="Form1"
HelpFile=""
Title="登记银行卡号系统"
ExeName32="登记银行卡号系统.exe"
Command32=""
Name="登记银行卡号系统"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="微软中国"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1

登记银行卡号系统.frm:

VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form Form1
BorderStyle = 4 'Fixed ToolWindow
Caption = "登记银行卡号系统"
ClientHeight = 6555
ClientLeft = 3135
ClientTop = 2385
ClientWidth = 11535
Icon = "登记银行卡号系统.frx":0000
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 6555
ScaleWidth = 11535
ShowInTaskbar = 0 'False
Begin VB.ComboBox Combo1
Height = 300
ItemData = "登记银行卡号系统.frx":0A02
Left = 7350
List = "登记银行卡号系统.frx":0A27
TabIndex = 5
Text = "中国工商银行 "
Top = 210
Width = 1695
End
Begin VB.Timer Timer1
Enabled = 0 'False
Interval = 1
Left = 5100
Top = 4290
End
Begin VB.CommandButton Command3
Caption = "导出Excel"
Height = 465
Left = 9900
TabIndex = 14
Top = 210
Width = 1305
End
Begin MSComctlLib.ProgressBar Pro
Height = 345
Left = 450
TabIndex = 13
Top = 3120
Visible = 0 'False
Width = 10365
_ExtentX = 18283
_ExtentY = 609
_Version = 393216
Appearance = 1
End
Begin MSComDlg.CommonDialog CommonDialog1
Left = 5970
Top = 4260
_ExtentX = 847
_ExtentY = 847
_Version = 393216
End
Begin VB.TextBox Text5
Height = 270
Left = 1050
TabIndex = 2
Text = "请输入确认ID"
Top = 720
Width = 1905
End
Begin VB.TextBox Text4
BeginProperty Font
Name = "宋体"
Size = 15
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 5100
Left = 2790
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 9
Top = 1290
Width = 8655
End
Begin VB.CommandButton Command2
Caption = "重输"
Height = 315
Left = 8640
TabIndex = 7
Top = 780
Width = 1065
End
Begin VB.CommandButton Command1
Caption = "输入"
Height = 315
Left = 7320
TabIndex = 6
Top = 765
Width = 1065
End
Begin VB.TextBox Text3
Height = 270
Left = 5070
TabIndex = 4
Text = "请输入确认银行卡号"
Top = 780
Width = 1905
End
Begin VB.TextBox Text2
Height = 270
Left = 5040
TabIndex = 3
Text = "请输入银行卡号"
Top = 210
Width = 1905
End
Begin VB.ListBox List1
Height = 5100
ItemData = "登记银行卡号系统.frx":0AB1
Left = 180
List = "登记银行卡号系统.frx":0AB3
TabIndex = 8
Top = 1290
Width = 2415
End
Begin VB.TextBox Text1
Height = 270
Left = 1050
TabIndex = 1
Text = "请输入ID"
Top = 210
Width = 1905
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "ID"
Height = 180
Left = 180
TabIndex = 12
Top = 735
Width = 180
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "确认银行卡号"
Height = 180
Left = 3900
TabIndex = 11
Top = 795
Width = 1080
End
Begin VB.Label YHKH
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "银行卡号"
Height = 180
Left = 4200
TabIndex = 10
Top = 225
Width = 720
End
Begin VB.Label XH
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "ID"
Height = 180
Left = 180
TabIndex = 0
Top = 225
Width = 180
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim conn, rs, Application, WorkBook, Sheet, i As Integer, j As Integer
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const INVALID_HANDLE_VALUE = -1
Private Const LB_FINDSTRING = &H18F

Dim selectIndex As Long

Private Sub Command1_Click()
If Text5 <> "" And Text5 <> Text1 Then
MsgBox "输入学号不一致"
ElseIf Text3 = "" Or Text3 <> Text2 Then
MsgBox "输入银行卡号不一致"
ElseIf List1.ListIndex = -1 Then
MsgBox "没有该记录,请确认该学号 "
ElseIf Len(Combo1.Text) > 25 Then
MsgBox "银行输入超长"
Else
If InStr(rs("id"), Trim(Text1)) > 0 Then
rs("user_yhkh") = Text3
rs("user_yh") = Combo1.Text
rs.Update
MsgBox "保存成功"
Else
rs.Close
rs.open "select * from [TrainAttendant] where id='" & Trim(Text1) & "'", conn, 1, 3
If Not rs.EOF Then
rs("user_yhkh") = Text3
rs("user_yh") = Combo1.Text
rs.Update
MsgBox "保存成功"
Else
MsgBox "未知错误"
End If
rs.Close
rs.open "select * from [TrainAttendant] order by id asc", conn, 1, 3
selectIndex = 0
End If
End If
End Sub

Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text5 = ""

End Sub

Private Sub Command3_Click()
CommonDialog1.Filter = "EXCEL文件|*.xls"
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then
Exit Sub
End If
Form1.Enabled = False
Set Application = CreateObject("Excel.Application") '建立EXCEL对象
Set WorkBook = Application.Workbooks.Add() '建立一个新的Excel文档
Set Sheet = WorkBook.Sheets(1) '选择sheet1
i = 0
rs.Close
rs.open "select * from [TrainAttendant] where len(trim(user_yhkh))>0 order by id asc", conn, 1, 3
For i = 0 To rs.fields.Count - 2
Sheet.Cells(1, i + 1).Value = changeName(rs.fields(i).Name)
Next
Pro.Value = 0
Pro.Visible = True
rs.movefirst
i = 1
j = 1
If Not rs.EOF Then
Pro.Max = rs.recordcount
Pro.Value = 1
End If
Timer1.Enabled = True
End Sub

Private Sub Form_Load()
selectIndex = 0
Set conn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
conn.open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\qinguanlieche"
rs.open "select * from [TrainAttendant] order by id asc", conn, 1, 3
Do While Not rs.EOF
List1.AddItem (rs("id"))
rs.movenext
Loop
rs.movefirst
End Sub

Private Sub Form_Unload(Cancel As Integer)
rs.Close
conn.Close
Set conn = Nothing
End Sub

Private Sub List1_Click()
If List1.ListIndex <> -1 Then
rs.Move List1.ListIndex - selectIndex, 0
selectIndex = List1.ListIndex
If Not (rs.EOF Or rs.bof Or List1.ListIndex = -1) Then
Dim i As Integer: i = 0
Text4 = ""
For i = 0 To rs.fields.Count - 2
Text4 = Text4 & changeName(rs.fields(i).Name) & " " & changeName2(rs.fields(i).Name, rs.fields(i).Value) & vbCrLf
Next
End If
Else
Text4 = "没有可用记录"
End If
End Sub

Private Sub Text1_GotFocus()
Text1.SelStart = 0
Text1.SelLength = Len(Text1)
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text5.SetFocus
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text3.SetFocus
End If
End Sub
Private Sub combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Call Command1_Click
End If
End Sub
Private Sub text3_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Combo1.SetFocus
End If
End Sub

Private Sub Text5_GotFocus()
Text5.SelStart = 0
Text5.SelLength = Len(Text5)
End Sub

Private Sub Text2_GotFocus()
Text2.SelStart = 0
Text2.SelLength = Len(Text2)
End Sub

Private Sub Text1_Change()
List1.ListIndex = SendMessage(List1.hwnd, LB_FINDSTRING, INVALID_HANDLE_VALUE, ByVal CStr(Text1.Text))
End Sub

Private Sub Text3_GotFocus()
Text3.SelStart = 0
Text3.SelLength = Len(Text3)
End Sub

Private Function changeName(str)
Select Case str
Case "ID": changeName = "ID"
Case "user_Yhkh": changeName = "银行卡号"
Case "user_Yh": changeName = "银行"
End Select
End Function

Private Function changeName2(str1, str2)
Select Case str1
case "id": changeName2 = str2
Case Else: changeName2 = str2
End Select
End Function

Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub

Private Sub Timer1_Timer()
If rs.EOF Then
WorkBook.saveas CommonDialog1.FileName
Timer1.Enabled = False
Pro.Visible = False
' Sheet.quit
' WorkBook.quit
Application.quit
Set Application = Nothing
Set WorkBook = Nothing
Set Sheet = Nothing
MsgBox "导出成功"
Form1.Enabled = True
rs.Close
rs.open "select * from [TrainAttendant] order by id asc", conn, 1, 3
selectIndex = 0
Else
Pro.Value = j
j = j + 1
For i = 0 To rs.fields.Count - 2
Sheet.Cells(j, i + 1).NumberFormatLocal = "@"
Sheet.Cells(j, i + 1).Value = CStr(changeName2(rs.fields(i).Name, rs.fields(i).Value) & " ")
Next
rs.movenext
End If
End Sub

Access数据库 qinguanlieche 数据表 TrainAttendant :
ID 自动编号
user_Yhkh 文本 25
user_Yh 文本 25

数据表我改过,楼主可以自己添加字段试试
刚刚测试过,没问题
用VB6.0打开调试会提示错误,但可以调试,主要是因为有个一非文本文件数据获取不到
楼主还有不明白的HI我吧
百度网友2ca1c0f24
2009-12-10 · TA获得超过2036个赞
知道大有可为答主
回答量:4364
采纳率:0%
帮助的人:3385万
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友9260c4507
2009-12-10 · TA获得超过2328个赞
知道大有可为答主
回答量:3736
采纳率:0%
帮助的人:2388万
展开全部
提问前可以先找找啊
很多问题都是有人问过的

http://zhidao.baidu.com/question/88577440.html
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
qoilizhen1989
2009-12-13
知道答主
回答量:3
采纳率:0%
帮助的人:0
展开全部
Dim a As String

Private Sub Combo1_Click()
If Combo1.ListIndex = 0 Then
Text1.Enabled = True
Text2.Enabled = True
Text3.Enabled = False
Combo3.Enabled = False
ElseIf Combo1.ListIndex = 1 Then
Text3.Enabled = True
Text1.Enabled = False
Text2.Enabled = False
Combo3.Enabled = False
ElseIf Combo1.ListIndex = 2 Then
Combo3.Enabled = True
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
End If

End Sub

Private Sub Command1_Click()
If Combo1.ListIndex = -1 Then
MsgBox "请选择查询方式", , "提示"
ElseIf Combo1.ListIndex = 0 Then
Adodc1.CommandType = adCmdUnknown
If Text2.Text = "" Then
MsgBox "查询范围上限不可为空", , "提示"
Else
Adodc1.RecordSource = "select * from 基本信息 where 年龄>= " & Text1.Text & " and 年龄<= " & Text2.Text & " "
Adodc1.Refresh
End If
ElseIf Combo1.ListIndex = 1 Then
Adodc1.CommandType = adCmdUnknown
If Text3.Text = "" Then
MsgBox "确定内容为空?"
Adodc1.RecordSource = "select*from 基本信息 where 学号='" & Text3.Text & "'"
Adodc1.Refresh
Else
Adodc1.RecordSource = "select*from 基本信息 where 学号='" & Text3.Text & "'"
Adodc1.Refresh
End If
ElseIf Combo1.ListIndex = 2 Then
Adodc1.CommandType = adCmdUnknown
Adodc1.RecordSource = "select * from 基本信息 where 专业='" & Combo3.Text & "' "
Adodc1.Refresh
End If

End Sub

Private Sub Command2_Click()
Adodc1.Recordset.AddNew
End Sub

Private Sub Command3_Click()
Adodc1.Recordset.Delete
End Sub

Private Sub Command4_Click()
Adodc1.CommandType = adCmdUnknown
Adodc1.RecordSource = "select * from 基本信息"
Adodc1.Refresh
End Sub

Private Sub Command5_Click()
a = InputBox("请输入查询对象字段", "自定义查询")
Adodc1.CommandType = adCmdUnknown
Adodc1.RecordSource = "select*from 基本信息 where a"
Adodc1.Refresh
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" + App.Path + "\" + "学生数据库.mdb"
Adodc1.CommandType = adCmdUnknown
Adodc1.RecordSource = "select * from 基本信息"
Adodc1.Refresh
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
fzsansi
2009-12-10
知道答主
回答量:28
采纳率:0%
帮助的人:13.6万
展开全部
用SQL吧!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
歧章窦曦
2019-06-20 · TA获得超过3820个赞
知道小有建树答主
回答量:3106
采纳率:26%
帮助的人:223万
展开全部
我发给你
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(4)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式