473,791 Members | 3,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Saving Image to database

Dav
Hi all,

I am using these code to save Image to database:
Dim fs As FileStream = New FileStream(file name, _
FileMode.OpenOr Create, FileAccess.Read )
Dim rawData() As Byte = New Byte(fs.Length) {}
fs.Read(rawData , 0, System.Convert. ToInt32
(fs.Length))
fs.Close()

OleDbDataAdapte r1.InsertComman d.CommandText = _
"Insert Into ImageTest Values (" & rawData & ")"
OleDbDataAdapte r1.InsertComman d.ExecuteNonQue ry()
MsgBox("Image saved to database")

But there is a problem in :
"Insert Into ImageTest Values (" & rawData & ")"

The error message is
Operator '&' is not defined for types 'String' and '1-
dimensional array of Byte'.

Anyone can help
Thanks
Nov 21 '05 #1
5 6375
Hi maybe this piece of code can help you

Dim ms As New System.IO.Memor yStream()
Dim arrImage() As Byte
PictureBox1.Ima ge.Save(ms, PictureBox1.Ima ge.RawFormat.Jp eg)
arrImage = ms.GetBuffer()
ms.Close()
Dim updCommand As SqlCommand
Try
updCommand = New SqlCommand("Upd ate table set bitmap= @bitmap where
code=@code)
updCommand.Para meters.Add(New SqlParameter("@ bitmap", SqlDbType.Image ))
updCommand.Para meters.Add(New SqlParameter("@ code", SqlDbType.Char) )
updCommand.Para meters("@code") .Value = 'Your code field
if arrImage Is Nothing Then
updCommand.Para meters("@bitmap ").Value = DBNull.Value
Else
updCommand.Para meters("@bitmap ").Value = arrImage
End If
updCommand.Conn ection = 'Your connection
updCommand.Conn ection.Open()
updCommand.Exec uteNonQuery()
updCommand.Conn ection.Close()

Catch ex As Exception
MsgBox(ex.tostr ing)
end try
"Dav" <an*******@disc ussions.microso ft.com> wrote in message
news:0d******** *************** *****@phx.gbl.. .
Hi all,

I am using these code to save Image to database:
Dim fs As FileStream = New FileStream(file name, _
FileMode.OpenOr Create, FileAccess.Read )
Dim rawData() As Byte = New Byte(fs.Length) {}
fs.Read(rawData , 0, System.Convert. ToInt32
(fs.Length))
fs.Close()

OleDbDataAdapte r1.InsertComman d.CommandText = _
"Insert Into ImageTest Values (" & rawData & ")"
OleDbDataAdapte r1.InsertComman d.ExecuteNonQue ry()
MsgBox("Image saved to database")

But there is a problem in :
"Insert Into ImageTest Values (" & rawData & ")"

The error message is
Operator '&' is not defined for types 'String' and '1-
dimensional array of Byte'.

Anyone can help
Thanks

Nov 21 '05 #2
"Dav" <an*******@disc ussions.microso ft.com> schrieb:
I am using these code to save Image to database:


If you store the images as a BLOB:

HOW TO: Read and Write a File to and from a BLOB Column by Using ADO.NET and
Visual Basic .NET
<URL:http://support.microso ft.com/?scid=kb;EN-US;316887>

HOW TO: Read and Write a File to and from a BLOB Column by Using Chunking in
ADO.NET and Visual Basic .NET
<URL:http://support.microso ft.com/?scid=kb;EN-US;317034>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
Herfried,

Did you look at the problem?
I cannot see what your links has to do with it.
Maybe can you edify me.

The problem is inserting in a database.

Cor
"Herfried K. Wagner [MVP]"
"Dav" <an*******@disc ussions.microso ft.com> schrieb:
I am using these code to save Image to database:


If you store the images as a BLOB:

HOW TO: Read and Write a File to and from a BLOB Column by Using ADO.NET
and
Visual Basic .NET
<URL:http://support.microso ft.com/?scid=kb;EN-US;316887>

HOW TO: Read and Write a File to and from a BLOB Column by Using Chunking
in
ADO.NET and Visual Basic .NET
<URL:http://support.microso ft.com/?scid=kb;EN-US;317034>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
Dav,

I don't see you use a dataset, so probably is this an answer what maybe can
be the solution for your problem.

\\\
Dim strSQL As String = "INSERT INTO imageTest (MyPictureField ) VALUES
(@MyParam)"
Dim cmd As New OleDbCommand(st rSQL, MyConnection)
cmd.Parameters. Add("@MyParam", rawData)
Conn.Open()
cmd.ExecuteNonQ uery()
///
I did not test it, however it should be something as this,

I hope it helps?

Cor

"Dav" <an*******@disc ussions.microso ft.com>
Hi all,

I am using these code to save Image to database:
Dim fs As FileStream = New FileStream(file name, _
FileMode.OpenOr Create, FileAccess.Read )
Dim rawData() As Byte = New Byte(fs.Length) {}
fs.Read(rawData , 0, System.Convert. ToInt32
(fs.Length))
fs.Close()

OleDbDataAdapte r1.InsertComman d.CommandText = _
"Insert Into ImageTest Values (" & rawData & ")"
OleDbDataAdapte r1.InsertComman d.ExecuteNonQue ry()
MsgBox("Image saved to database")

But there is a problem in :
"Insert Into ImageTest Values (" & rawData & ")"

The error message is
Operator '&' is not defined for types 'String' and '1-
dimensional array of Byte'.

Anyone can help
Thanks

Nov 21 '05 #5
"Cor Ligthert" <no************ @planet.nl> schrieb:
The problem is inserting in a database.


I know that.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3305
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent the file to wordpad, it shows
2
4004
by: Brad | last post by:
I have code which takes an image, uploaded from a web page, and saves it to a database. Now I want to always resize an uploaded image before it is saved to the database. My code to resize is below and of course it's not working properly because my web page which displays the resulting image from the database is not showing the image. I **think** the problem is in my converting the bitmap back to a byte array. If I change my code back...
12
2014
by: tjonsek | last post by:
I get a generic error (not very helpful) when attempting to save a re-sized image back to its original location. Here is the code snippet: Dim g As System.Drawing.Image = System.Drawing.Image.FromFile(Me.File1.Value) Dim thisFormat = g.RawFormat Dim imgOutput As New Bitmap(g, 800, 600) Dim strFileType As String Dim strFileName As String = File1.PostedFile.FileName
5
16131
by: Mark | last post by:
I have a VB 6 program that I have saved an audio file to using DAO and the appendchunk as is shown at http://support.microsoft.com/kb/103257/EN-US/. ; I have it working fine in that app (it saves to an access database and I can save the data back to a file using getchunk and everything works correctly). The issue is that I am now trying to access the database in VB.NET 2003 through an OleDBDataAdapter (Jet 4.0 connection) and can't get it...
6
8125
by: Jeff | last post by:
Hey (and thank you for reading my post) In visual web developer 2005 express edition I've created a simple website project.. At this website I want users who register to be able to upload a picture of themselves to their profile... I admit that I'm a newbie... but this is how I understand this:
6
6455
by: Mark Denardo | last post by:
My question is similar to one someone posted a few months back, but I don't see any replies. Basically I want to be able to have users upload photos and save them in a database (as byte data) and be able to load them to an image webcontrol, but system.web.ui.webcontrols.image only seems to have a control to load the image from a URL. There's no way to load this directly without saving the image as a file and then using...
2
3563
by: tomlebold | last post by:
It takes five minutes when using object linking and embedding to save a PDF file using a normal from. The data type is image in an SQL Sever table. We are trying to keep track of the legal documents that we have purchased. Is their a better technique to use, rather saving the PDF file . Could we save the path to a text or varchar datatype.
3
1758
by: mirianCalin | last post by:
the code saves the category, image title, image, and feature.. but the problem is that the "feature" is not saved, but the others were saved.. this is the data types of my table category = text title = text image = longblob feature = text in html, the users input the feature in (textarea)..
2
1624
by: keerthisreenu | last post by:
hai to all...!! iam working with Ms Access 2000. iam saving an image in the database. After that i want to retrive the same image from database and displaying it in the picture box. but its not working. why it is happening? please help me. iam sending the code. when button1 clicks it store in database. when button2 clicks it should display in picturebox.
10
7442
by: Nathan Sokalski | last post by:
I am using ASP.NET 2.0, and need to know how to save and use an image that is stored in an SQL Server image datatype. How can I do this using ASP.NET? Thanks.
0
9669
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10427
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10155
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.