[这个贴子最后由清风流水在 2005/08/23 08:37pm 第 1 次编辑]
最近用VB通宵做个图书管理系统,但是有错没法继续了
请大家帮帮忙,我的QQ327703857,要用到连接数据库的知识
谢谢了,感激不尽!!!
Dim rs As ADODB.Recordset
Public s1 As String
Private Sub Cmdadd_Click(Index As Integer)
Dim Sql As String
Dim i As Integer
Call showed
Select Case Index
Case 0
Call Cmbstyled
For i = 1 To 5
Txtlib(i).Text = ""
Next
Txtlib(6).Text = "1"
'; Txtlib(0).Text = "BK" & Right("000" & (s1 + 1), 3)
Cmbstyle.Text = "---请输入类型---"
Case 1
If Txtlib(1).Text = "" Then
MsgBox "书名不能为空!!"
Txtlib(1).SetFocus
ElseIf Txtlib(2).Text = "" Then
MsgBox "作者不能为空!!"
Txtlib(2).SetFocus
ElseIf Txtlib(3).Text = "" Then
MsgBox "出版日期不能为空!!"
Txtlib(3).SetFocus
MsgBox Date & "以前"
ElseIf Txtlib(4).Text = "" Then
MsgBox "出版社不能为空!!"
Txtlib(4).SetFocus
ElseIf Cmbstyle.Text = "" Or Cmbstyle.Text = "---请输入类型---" Then
MsgBox "图书类型不能为空!!"
Cmbstyle.SetFocus
ElseIf Txtlib(5).Text = "" Then
MsgBox "关键字不能为空!!"
Txtlib(5).SetFocus
ElseIf Txtlib(6).Text = "" Then
MsgBox "数量不能为空!!"
Txtlib(6).SetFocus
ElseIf Txtlib(3).Text <= Date Then
Sql = "insert into library values(';" & Txtlib(0).Text & _
"';,';" & Txtlib(1).Text & "';,';" & Txtlib(2).Text & "';,';" & _
Txtlib(3).Text & "';,';" & Txtlib(4).Text & "';,';" & Cmbstyle.Text & _
"';,';" & Txtlib(5).Text & "';," & Val(Txtlib(6).Text) & ")"
Call Con_Exectue(Sql)
MsgBox "成功入库!!"
Else
MsgBox "日期错误!!"
Txtlib(3).SetFocus
MsgBox Date & "以前"
End If
Case 2
Set jk = Nothing
Unload Me
MDIFrmmain.Show
';Case 3
End Select
End Sub
Private Sub Cmdmove_Click(Index As Integer)
Select Case Index
Case 0
rs.MoveFirst
Case 1: rs.MovePrevious
If rs.BOF Then rs.MoveFirst
Case 2: rs.MoveNext
If rs.EOF Then rs.MoveLast
Case 3: rs.MoveLast
End Select
Call TxtData
End Sub
Private Sub Form_Load()
Set rs = GetRs("library")
Call TxtData
';Call showed
';Cmbstyle.AddItem "小说"
';Cmbstyle.AddItem "外国文学"
';Cmbstyle.AddItem "扯蛋"
';Cmbstyle.AddItem "列传"
';Cmbstyle.AddItem "幼稚园读物"
';Cmbstyle.AddItem "学习用书"
End Sub
Sub showed()
Call library
jk.Open "library"
jk.MoveLast
s1 = jk.Fields(0).Value
jk.Close
Set jk = Nothing
Txtlib(0).Text = "BK" & Right("000" & (s1 + 1), 3)
End Sub
Sub TxtData() ';向文本框添加信息
Txtlib(0).Text = "BK" & Right("000" & rs.Fields(0).Value, 3)
Txtlib(1).Text = rs.Fields(1).Value
Txtlib(2).Text = rs.Fields(2).Value
Txtlib(3).Text = rs.Fields(3).Value
Txtlib(4).Text = rs.Fields(4).Value
Cmbstyle.Text = rs.Fields(5).Value
Txtlib(5).Text = rs.Fields(6).Value
Txtlib(6).Text = rs.Fields(7).Value
End Sub
Sub Cmbstyled()
Cmbstyle.AddItem "小说"
Cmbstyle.AddItem "外国文学"
Cmbstyle.AddItem "扯蛋"
Cmbstyle.AddItem "列传"
Cmbstyle.AddItem "幼稚园读物"
Cmbstyle.AddItem "学习用书"
End Sub
下面是模块
Public jk As ADODB.Recordset
';Dim cn As New ADODB.Connection
';Dim rs As New ADODB.Recordset
';cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbadd
Sub library()
Set jk = New ADODB.Recordset
jk.ActiveConnection = "file name=library.udl"
jk.CursorLocation = adUseClient
jk.CursorType = adOpenDynamic
jk.LockType = adLockOptimistic
End Sub
Public Sub Con_Exectue(Str As String)
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "file name=library.udl"
'; Cn.Open
'; Cn.Execute Str
'; Cn.Close
Set cn = Nothing
End Sub
Public Function GetRs(Str As String) As ADODB.Recordset
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
'; Rs.ActiveConnection = "file name=library.udl"
'; Rs.CursorType = adOpenStatic
'; Rs.LockType = adLockOptimistic
rs.Open Str, "file name=library.udl", adOpenStatic, adLockOptimistic
'; Rs.Source = "library"
Set GetRs = rs
End Function
Public Sub dblink()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Provider=library.udl" & dbadd
End Sub
|