hi.. i tried to put picture on our system. in the employee form.. but i dont know the exact step on how.


i have here a code for opening the picture.. but i dont know how to save it in my database together with the information of the employee... here my code


cd.Filter = "PictureFile(*.jpg,*.bmp,*.gif)|*.jpg|*.gif|*.bmp|"
cd.ShowOpen
Image1.Picture = LoadPicture(cd.FileName)

i tried to use a field with an oleobject but i dont know how to work well..

this my saving procedure


Sub saverecord()

rsemployee.AddNew
rsemployee.Fields("EmployeeID") = txt1.Text
rsemployee.Fields("EmployeeName") = txt2.Text
rsemployee.Fields("EmployeePosition") = txt3.Text
rsemployee.Fields("Address") = txt4.Text
rsemployee.Fields("Age") = txt5.Text
rsemployee.Fields("Gender") = txt6.Text
rsemployee.Fields("PhoneNo") = txt7.Text
rsemployee.Fields("picture") = cd.FileName
rsemployee.Update

End Sub

i need an clear stepss...kindly help me....

thxxxxxxx

jaasaria

Recommended Answers

All 16 Replies

i guest u want to save path of the picture.
this way is the easiest. but you must to put the picture on one folder. don't try to move the picture that you was saved it. if you move the picture, you will get an error..

commented: though of post +1

can you give me the exact process??
on how to make that picture saving..

even that it has the disadvantages.. i would like see the way it process..

thxx alwayzzzzzzzzzz

hi jaasaria,
>>can you give me the exact process??
what of exact process?
are u have visiting the site from ptolchin?
in there you can see the faq about this thread.

thxxxxxxx for the help.... thxx a lot guyzzzzzzz

It is always better to store the picture in a LOB field in database after converting the file into a byte stream . It ensures that no data is lost . So you don't have to bother about location of all the files.

elow... can you make it step 2 step..
actually im only novice in vb...

can i??

Try to use this sample code

Dim CN As New ADODB.Connection
Dim RS As ADODB.Recordset
Dim DataFile As Integer, Fl As Long, Chunks As Integer
Dim Fragment As Integer, Chunk() As Byte, i As Integer, FileName As String

Private Const ChunkSize As Integer = 16384
Private Const conChunkSize = 100

Private Sub cmdSave_Click()
    CN.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Data Source=Test"
    Dim strSQL As String

    strSQL = "SELECT * FROM pub_info where pub_id = '9999'"
    RS.Open strSQL, CN, adOpenForwardOnly, adLockOptimistic

    RS.AddNew
      SavePicture
    RS.Update

    Set RS = Nothing
    Set RS = New Recordset
End Sub

Private Sub SavePicture()
    Dim strFileNm As String
    DataFile = 1
    Open strFileNm For Binary Access Read As DataFile
        Fl = LOF(DataFile)   ' Length of data in file
        If Fl = 0 Then Close DataFile: Exit Sub
        Chunks = Fl \ ChunkSize
        Fragment = Fl Mod ChunkSize
        ReDim Chunk(Fragment)
        Get DataFile, , Chunk()
        RS!logo.AppendChunk Chunk()
        ReDim Chunk(ChunkSize)
        For i = 1 To Chunks
            Get DataFile, , Chunk()
            RS!logo.AppendChunk Chunk()
        Next i
    Close DataFile
End Sub

thx a lot dude......thxxxxx for sharing your knowledge..^_^

hi how to make trial Programs thanks alot
criteria --> with date, if that it change, programs gives some critical. thanks

hi z3r0_vb...
welcome to daniweb friend...
please don't hijack other post.
make a new thread and give title agree with your problems and describe your problem. many people will give you help :)

happy coding.

Try to use this sample code.

Dim CN As New ADODB.Connection
Dim RS As ADODB.Recordset
Dim DataFile As Integer, Fl As Long, Chunks As Integer
Dim Fragment As Integer, Chunk() As Byte, i As Integer, FileName As String

Private Const ChunkSize As Integer = 16384
Private Const conChunkSize = 100

Private Sub Form_Load()
    CN.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Data Source=Test"
    Dim strsql As String

    strsql = "SELECT * FROM pub_info where pub_id = '9999'"
    RS.Open strsql, CN, adOpenForwardOnly, adLockReadOnly
      ShowPic
    Set RS = Nothing
    Set RS = New Recordset
End Sub

Private Sub ShowPic()
    DataFile = 1
    Open "pictemp" For Binary Access Write As DataFile
        Fl = RS!logo.ActualSize ' Length of data in file
        If Fl = 0 Then Close DataFile: Exit Sub
        Chunks = Fl \ ChunkSize
        Fragment = Fl Mod ChunkSize
        ReDim Chunk(Fragment)
        Chunk() = RS!logo.GetChunk(Fragment)
        Put DataFile, , Chunk()
        For i = 1 To Chunks
            ReDim Buffer(ChunkSize)
            Chunk() = RS!logo.GetChunk(ChunkSize)
            Put DataFile, , Chunk()
        Next i
    Close DataFile
    FileName = "pictemp"
    Picture1.Picture = LoadPicture(FileName)
End Sub

sir, i want to display it together with my dataemployee...

sir, can you make it more easier.

i can't directly edit it as a proffesional.

can you give me an attachment... plzzzzzzzzzzz
im beging with u...

You just need to make some changes to the code to suit your requirment. I think you don't have to make any changes to ShowPic()

You just need to make some changes to the code to suit your requirment. I think you don't have to make any changes to ShowPic()

actually i cant get it.
sir, thx for the help. I already try it but error has been occur.
maybe i will be looking in the another site. thxxxx for help.

it's all ok....

jaasaria

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.