473,394 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

inserting images from PictureBox in to the oracle database

Hi,
This is HARSHAD,
I am creating a project in VB.NET
for managing details like photos of criminals.
but i am facing problems in converting a image in to filestream so that it can be inserted in to the oracle 10g database using BLOB variable type.
if you can help me it will be very helpful..

This is my code:
---------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. Imports System
  2. Imports System.IO
  3. Imports System.Windows.Forms
  4. Imports System.Data                 ' VB.NET
  5. Imports System.Drawing.Imaging
  6. Imports System.Collections
  7. Imports System.ComponentModel
  8. 'Imports System.Data.OracleClient    ' Oracle Client
  9. Imports Oracle.DataAccess.Client
  10. --------------------------------------------------------------------------------------------------------------
  11. Private Sub Insert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  12.  
  13.         Dim imagename As String
  14.         Dim conn As OracleConnection = New OracleConnection
  15.         ' Specify the connect string
  16.         conn.ConnectionString = "User Id=system;Password=tiger;Data Source=;"
  17.         ' Create the OracleCommand object
  18.         Dim cmd As OracleCommand = New OracleCommand
  19.         Dim bsize As Integer
  20.         Try
  21.             ' Open the connection
  22.             conn.Open()
  23.             MessageBox.Show("Connection to Oracle database established!")
  24.             'Console.WriteLine(" ")
  25.  
  26.             If (imagename <> "") Then
  27.                 MessageBox.Show("Please load the Image")
  28.             Else
  29.                 Try
  30.                     Dim fls As System.IO.FileStream(imagename,IO.FileMode.Open, IO.FileAccess.Read)
  31.                     'fls = New FileStream(imagename, FileMode.Open, FileAccess.Read, FileShare.Read, bsize, True)
  32.                     'fls = New FileStream(imagename, FileMode.Open, FileAccess.Read)
  33.                     Dim blob(fls.Length - 1) As Byte
  34.                     fls.Position = 0
  35.                     fls.Read(blob, 0, System.Convert.ToInt32(fls.Length))
  36.                     fls.Close()
  37.                     Dim blobParameter As OracleParameter = New OracleParameter
  38.                     blobParameter.OracleDbType = OracleDbType.Blob
  39.                     blobParameter.ParameterName = "BlobParameter"
  40.                     blobParameter.Value = blob
  41.                     Dim cmdQuery = "INSERT into ARREST values('" & TextBox1.Text & "','" & TextBox4.Text & "','" & TextBox6.Text & "','" & TextBox8.Text & "','" & TextBox11.Text & "','" & ComboBox1.Text & "','" & ComboBox2.Text & "','" & ComboBox3.Text & "','" & TextBox12.Text & "','" & TextBox13.Text & "','" & ComboBox4.Text & "','" & ComboBox5.Text & "','" & ComboBox10.Text & "','" & TextBox15.Text & "','" & TextBox18.Text & "','" & TextBox19.Text & "','" & TextBox23.Text & "','" & TextBox25.Text & "','" & TextBox26.Text & "','" & TextBox27.Text & "','" & TextBox28.Text & "',:BlobParameter,:BlobParameter ,'" & TextBox7.Text & "','" & ComboBox6.Text & "','" & TextBox10.Text & "','" & ComboBox7.Text & "','" & TextBox39.Text & "','" & TextBox54.Text & "','" & TextBox41.Text & "','" & TextBox43.Text & "','" & TextBox44.Text & "','" & TextBox45.Text & "','" & ComboBox14.Text & "','" & ListBox1.Text & "',)"
  42.                     ' Create the OracleCommand object
  43.                     cmd = New OracleCommand(cmdQuery)
  44.                     cmd.Connection = conn
  45.                     cmd.CommandType = CommandType.Text
  46.                     cmd.Parameters.Add(blobParameter)
  47.                     cmd.ExecuteNonQuery()
  48.                     MessageBox.Show("added to blob field")
  49.                     cmd.Dispose()
  50.                     conn.Close()
  51.                     conn.Dispose()
  52.                 Catch ex As Exception
  53.                     MessageBox.Show(ex.StackTrace)
  54.                 End Try
  55.             End If
  56.         Catch ex As Exception
  57.             MessageBox.Show(ex.StackTrace)
  58.         End Try
  59.  
  60.    End Sub
Apr 2 '07 #1
0 1584

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Mat | last post by:
Hi, I have a system that uploads images as BLOBs in a database. I also have a function that I use to resize uploaded images before saving as files. I would like to combine these two by resising...
18
by: Andrew Christiansen | last post by:
Hey all. The images I create in photoshop with semi-transparent pixels (for instance in Photoshop text with a dropshadow with a transparent canvas) I've been saving in PNG format and then using...
3
by: Alan | last post by:
Hi, I'm converting a database application from Access 97 to C#/SQL Server. Old database contains some images in OLE fields. I've figured out that there's OLE header preceeding actual image data...
0
by: Marcus Kwok | last post by:
I have written a class (Windows Form) in Managed C++ that accepts an array of image filenames and will display them sequentially. All images will be the same size. I got it to work, but I know...
2
by: clinttoris | last post by:
Hello, If someone could help me it would be appreciated as I am not having much luck. I'm struggling with my asp code and have some questions relating to asp and oracle database. First...
4
by: =?Utf-8?B?U3BlZWR5?= | last post by:
Hi there, I am currently writing an application where one inspects images and annotates certain features. Thus, one has to zoom in (4x) and pan around. The features are marked with little red...
1
by: san123456789 | last post by:
Hi, Im using a MS SQL server to store images... Im creating a windows form application using C#. I need to store and retrieve images from the database. This is my code to store images: ...
1
by: Amnu | last post by:
Hi there, I've been told to write a custom control using C#.NET ( 2.0 ). This control should be able to display images and give access to zoom functionality. I've visited numerous How-To pages...
18
by: boss1 | last post by:
Hi all, i m having a problem with inserting data in oracle db. When i use form action =(call self page) then data is inserting properly.But problem with when using form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.