?? module1.bas
字號:
Attribute VB_Name = "Module1"
Public flag As Integer
Public bflagadd As Integer
Public flagadd As Integer
Public brflagadd As Integer
Public filename As String
Public Function ConnectString() As String
ConnectString = "FileDSN=zhozhiyonxsbook.dsn;UID=sa;PWD="
End Function
Public Function ExecuteSQL(ByVal SQL As String, MsgString As String) As ADODB.Recordset
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
cnn.Open ConnectString
Set rst = New ADODB.Recordset
rst.Open Trim$(SQL), cnn, adOpenKeyset, adLockOptimistic
Set ExecuteSQL = rst
End Function
Public Sub SavetoDB(diskFile As String, jszh As String)
Dim bytedata() As Byte
Dim numblocks As Long
Dim filelength As Long
Dim leftover As Long
Dim sourcefile As Long
Dim i As Long
Const BLOCKSIZE = 4096
Dim cnn As ADODB.Connection
Dim ADOrst As New ADODB.Recordset
Dim fld As ADODB.Field
Set cnn = New ADODB.Connection
cnn.Open ConnectString
ADOrst.Open "zzyxs", cnn, adOpenDynamic, adLockOptimistic
Do While Trim(ADOrst("借書證號").Value) <> Trim(jszh) And Not ADOrst.EOF
ADOrst.MoveNext
Loop
If Not ADOrst.EOF Then
Set fld = ADOrst("照片")
Else
Exit Sub
End If
sourcefile = FreeFile
Open diskFile For Binary Access Read As sourcefile
filelength = LOF(sourcefile)
If filelength = 0 Then
Close sourcefile
MsgBox diskFile & "無內(nèi)容或內(nèi)容不存在!"
Else
numblocks = filelength \ BLOCKSIZE
leftover = filelength Mod BLOCKSIZE
fld.Value = Null
ReDim bytedata(BLOCKSIZE)
For i = 1 To numblocks
Get sourcefile, , bytedata()
fld.AppendChunk bytedata()
Next i
ReDim bytedata(leftover)
Get sourcefile, , bytedata()
fld.AppendChunk bytedata()
Close sourcefile
ADOrst!FileLen = filelength
ADOrst.Update
ADOrst.Close
cnn.Close
End If
End Sub
Public Sub getfromDB(diskFile As String, jszh As String)
Dim bytedata() As Byte
Dim numblocks As Long
Dim filelength As Long
Dim leftover As Long
Dim sourcefile As Long
Dim i As Long
Const BLOCKSIZE = 4096
Dim cnn As ADODB.Connection
Dim ADOrst As New ADODB.Recordset
Dim fld As ADODB.Field
Set cnn = New ADODB.Connection
cnn.Open ConnectString
ADOrst.Open "zzyxs", cnn, adOpenDynamic, adLockOptimistic
Do While Trim(ADOrst("借書證號").Value) <> Trim(jszh) And Not ADOrst.EOF
ADOrst.MoveNext
Loop
If Not ADOrst.EOF Then
Set fld = ADOrst("照片")
Else
Exit Sub
End If
sourcefile = FreeFile
Open diskFile For Binary As sourcefile
filelength = ADOrst!FileLen
If IsNull(filelength) Or filelength = 0 Then
Close sourcefile
MsgBox diskFile & "無內(nèi)容或不存在!"
Else
numblocks = filelength \ BLOCKSIZE
leftover = filelength Mod BLOCKSIZE
For i = 1 To numblocks
bytedata() = fld.GetChunk(BLOCKSIZE)
Put sourcefile, , bytedata()
Next i
ReDim bytedata(leftover)
bytedata() = fld.GetChunk(leftover)
Put sourcefile, , bytedata()
Close sourcefile
ADOrst.Close
cnn.Close
End If
End Sub
Sub main()
flag = 0
frmmain.Show
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -