Solved

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

Posted on 2004-10-13
3
248 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
3 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 250 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now