1.

How To Store/retrive Images Into/from Oracle Database Using Vb.net ?

Answer»

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, adOpen Dynamic, adLock Optimistic
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 style image.*, (select COMPANY name 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

Code for storing Image

code for retriving images



Discussion

No Comment Found