How to store/retrive images into/from oracle database using vb.net

Showing Answers 1 - 4 of 4 Answers

manju

  • Oct 18th, 2006
 

HiThere r 2 ways in sql server1.Binary encodind2.path storage

  Was this answer useful?  Yes

Niraj

  • Nov 7th, 2006
 

Hi you can ado streams which is available in ado 2.5 or above. I m giving you a source code of vb using sql server but this will be very much helpful for you. In case if u still have problems then pls contact.

Niraj

Code for storing Image

Dim rs As New ADODB.Recordset
Dim mstream As New ADODB.Stream

rs.Open "select * from StyleImage where styleNo='" & TxtStyleNo.Text & "'", db, adOpenDynamic, adLockOptimistic

If rs.EOF = False Then
    MsgBox "Stle Already Exist in Database"
    Exit Sub
End If

db.Execute "exec insertintostyleimage " & MCId & "," & SCId & "," & GId & "," & CompanyId & ",'" & TxtStyleNo & "','" & TxtStyleDesc & "','" & TxtStyleCost & "','" & Img1.Picture & "','" & Usercd & "','" & Img2.Picture & "','" & cmbexportername.Text & "','" & txtexporterstyleno.Text & "'"

rs.Open "select * from StyleImage where styleNo='" & TxtStyleNo.Text & "'", db, adOpenDynamic, adLockOptimistic

With rs
If .RecordCount <> 0 And Img1.Picture <> LoadPicture("") And Img2.Picture <> LoadPicture("") Then
 
      mstream.Type = adTypeBinary
      mstream.Open
      fpath = CD1.FileName
      mstream.LoadFromFile fpath
      .Fields("imagefilebig").Value = mstream.Read
      fpath = CD2.FileName
      mstream.LoadFromFile fpath
      .Fields("imagefilesmall").Value = mstream.Read
      .Update
      mstream.Close
 
End If
       .Close
End With

code for retriving images

Dim rscat As New ADODB.Recordset
Dim mstream As New ADODB.Stream

rscat.Open "select styleimage.*,(select companyname from exporter where companyid=styleimage.exporterid)as expname from styleimage where companyid=" & CompanyId & " and maincatid=" & MCId & " and subcatid=" & SCId & " and catgroupid=" & GId & " and styleno='" & CmbStyleNo & "'", db, adOpenDynamic, adLockOptimistic
    If rscat.RecordCount > 0 Then
        mstream.Type = adTypeBinary
        Set Img2.Picture = LoadPicture("")
        If mstream.State = 1 Then mstream.Close
        mstream.Open
        If IsNull(rscat.Fields("Imagefilesmall")) Then
        Else
            mstream.Write rscat.Fields("Imagefilesmall").Value
            If mstream.Size > 1 Then
                mstream.SaveToFile App.Path & "temp.jpeg", adSaveCreateOverWrite
                CD1.FileName = App.Path & "temp.jpeg"
                Img2.Picture = LoadPicture(CD1.FileName)
                mstream.Close
            End If
        End If
   

  Was this answer useful?  Yes

chirag

  • Dec 2nd, 2006
 

i want to store word/excel/text file into sql server database from vb.net and also want to retrieve it give source code and explanation

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions