PDA

View Full Version : Giup toi voi



lovely
11-09-2002, 16:19
Ban nao da tung lam ct quan ly nhan su cho hoi chut
Lam cach nao ta co the nhap duoc anh(them xua xoa luu)
Tuc la tuong ung voi 1 record se co 1 anh
Minh can rat gap
Thank for all help:o
ITbaby: Đề nghị lần sau anh hãy gõ bài bằng tiếng việt có dấu và tiêu đề cần rõ ràng chút nhé ! Nếu chưa có bài Reply thì baby đã move nó vào thùng rác rồi đấy :)

hades_dino
12-08-2005, 15:38
bạn hãy sử dụng OLE trong database access để lữu trữ các hình ảnh

gurupt
15-08-2005, 08:52
* Bạn dùng hàm này để lưu ảnh:

Public Sub SaveBitmap(ByRef adoRS As ADODB.Recordset, ByVal strField As String, ByVal SourceFile As String)
Dim Arr() As Byte
Dim Pointer As Long
Dim SizeOfThefile As Long

Pointer = lOpen(SourceFile, OF_READ)
'size of the file
SizeOfThefile = GetFileSize(Pointer, lpFSHigh)
lclose Pointer
ReDim Arr(SizeOfThefile)
Open SourceFile For Binary Access Read As #1
Get #1, , Arr
Close #1
adoRS(strField).Value = Arr
Exit Sub
End Sub


Giải thích :
- adoRS là recordet cần lưu ảnh
- strField là Field lưu ảnh
- Source file là tập tin ảnh cần lưu vào Database

* Sau đó dùng các hàm này để đọc ảnh :

Private Function WriteBLOB(T As ADODB.Recordset, sField As String, Destination As String)
On Error GoTo Err_WriteBLOB
Dim DestFile As Integer, FileLength As Long
Dim FileData() As Byte
' Get the length of the file.
FileLength = T(sField).ActualSize()
ReDim FileData(FileLength)
If FileLength <> 0 Then
DestFile = FreeFile
Open Destination For Binary Access Write Lock Write As DestFile
FileData() = T(sField).Value
Put DestFile, , FileData()
Close DestFile
End If
WriteBLOB = 1
Exit Function
Err_WriteBLOB:
MsgBox Err.Description
WriteBLOB = 0
Exit Function
End Function

'Dùng hàm này để đọc ảnh đã lưu nhé
Private Sub ReadImage(strImage As String, IMGID As Long, Optional strFolder As String)
Dim cn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim response As String
' Open the datbase and then recordset containing the images
cn.CursorLocation = adUseClient
cn.ConnectionString = StrConnect
cn.Open
rst.Open "SELECT * FROM TABLEIMAGE where IMGID = " & IMGID & "", cn, adOpenStatic, adLockOptimistic
' Write image to disk if found in recordset
If Not rst.EOF And Not rst.BOF Then
Call WriteBLOB(rst, "PERSONIMG", strImage) 'PERSONIMG : field chứa ảh OLE Object
'Bạn đọc ảnh vào PictureBox
'frmMain.Picture1.Picture = LoadPicture(strImage)
'frmMain.Picture1.Refresh
Else
response = MsgBox("Không tìm thấy", vbOKOnly + vbExclamation, "Error")
End If
' Close recordset and database
rst.Close
cn.Close
' Release variables
Set rst = Nothing
Set cn = Nothing
End Sub


Có gì không hiểu bạn mail cho mình : baohuymail@yahoo.com