Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to store an image in Oracle as a BLOB using vb.net?

Posted on 2004-10-13
3
Medium Priority
?
273 Views
Last Modified: 2008-01-09
Hi,
   I want to store an image in Oracle database as a BLOB. How do I do it using vb.net and also How do I read the image and display it in the application?
Thanks in advance,
regards,
Badri.
0
Comment
Question by:gvsbnarayana
1 Comment
 
LVL 10

Accepted Solution

by:
123654789987 earned 1000 total points
ID: 12306520
This is an example of inserting blob values to a sql server database. Instead of Sql Server use Oracle:

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO

Public Class EmployeeData

  Public Shared Sub Main()
    Dim hireDate As DateTime = DateTime.Parse("5/21/99")
    AddEmployee("Jones", "Mary", "Sales Representative", hireDate, 5, "jones.bmp")
  End Sub

  Public Shared Sub AddEmployee(lastName As String, firstName As String, title As String, hireDate As DateTime, _
                                reportsTo As Integer, photoFilePath As String)

    Dim photo() as Byte = GetPhoto(photoFilePath)

    Dim nwindConn As SqlConnection = New SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;")

    Dim addEmp As SqlCommand = New SqlCommand("INSERT INTO Employees (LastName, FirstName, Title, HireDate, ReportsTo, Photo) " & _
                                              "Values(@LastName, @FirstName, @Title, @HireDate, @ReportsTo, @Photo)", nwindConn)

    addEmp.Parameters.Add("@LastName",  SqlDbType.NVarChar, 20).Value = lastName
    addEmp.Parameters.Add("@FirstName", SqlDbType.NVarChar, 10).Value = firstName
    addEmp.Parameters.Add("@Title",     SqlDbType.NVarChar, 30).Value = title
    addEmp.Parameters.Add("@HireDate",  SqlDbType.DateTime).Value     = hireDate
    addEmp.Parameters.Add("@ReportsTo", SqlDbType.Int).Value          = reportsTo

    addEmp.Parameters.Add("@Photo",     SqlDbType.Image, photo.Length).Value = photo

    nwindConn.Open()

    addEmp.ExecuteNonQuery()

    nwindConn.Close()
  End Sub

  Public Shared Function GetPhoto(filePath As String) As Byte()
    Dim fs As FileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)
    Dim br As BinaryReader = new BinaryReader(fs)

    Dim photo() As Byte = br.ReadBytes(fs.Length)

    br.Close()
    fs.Close()

    Return photo
  End Function
End Class
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question