473,320 Members | 2,193 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,320 software developers and data experts.

Saving image to Sybase

Hi.
I'm trying to save an image into a Sybase DB. The field (image_1) is of type
"Blob". I have found two examples that I've tried, but no luck so far.
Here is what I have done:

Example 1:
strSqlImage = _
"UPDATE" & _
" table_1" & _
" SET" & _
" image_1 = ?" & _
" WHERE" & _
" id = " & ID

cmd = New OleDbCommand(strSqlImage, conn)

Dim fileStream As New System.IO.FileStream(strFilePath, IO.FileMode.Open,
IO.FileAccess.Read)
Dim b(fileStream.Length) As Byte

fileStream.Read(b, 0, b.Length)
fileStream.Close()

Dim P As New OleDbParameter("@Picture", OleDbType.VarBinary, b.Length,
Data.ParameterDirection.Input, False, 0, 0, Nothing,
Data.DataRowVersion.Current, b)
cmd.Parameters.Add(P)
conn.Open()

cmd.ExecuteNonQuery()
conn.Close()

The code gave me this error:
"[Native Error code: 1622][DataDirect ADO Sybase Provider] Type '"
Example 2:
Dim FileLength As Integer
Dim UpFile As System.Web.HttpPostedFile = txtFile.PostedFile

FileLength = UpFile.ContentLength
Dim FileByteArray(FileLength) As Byte
Dim StreamObject As System.IO.Stream = UpFile.InputStream
StreamObject.Read(FileByteArray, 0, FileLength)

strSqlImage = _
"UPDATE" & _
" table_1" & _
" SET" & _
" image_1 = ?" & _
" WHERE" & _
" id = " & ID

conn.Open()
cmd = New OleDbCommand(strSqlImage, conn)

cmd.Parameters.Add(New OleDbParameter("@Picture",
OleDbType.Binary)).Direction = System.Data.ParameterDirection.Input
cmd.Parameters("@Picture").Value = FileByteArray

cmd.ExecuteNonQuery()
conn.Close()

The code gave me this error:
"Conversion failed for command parameter[0]'@ Picture' because the data
value overflowed the type used by the provider."

I'm using "Sybase ASE OLE DB Provider" to connect to the DB. The Sybase DB
is version 11.9

I'm stuck here so please help me!

Thanks,
Shawn

Nov 18 '05 #1
1 6973
The problem is solved!
One of the examples was taken from Microsoft, it was written in C#. Today I
found the same example written in VB.NET and found one difference. The C#
example used OleDbType.VarBinary and the VB.NET example used
OleDbType.LongVarBinary. By using the LongVarBinary type my code worked.

Shawn
"Shawn" <bo********@hotmail.com> wrote in message
news:eh****************@TK2MSFTNGP12.phx.gbl...
Hi.
I'm trying to save an image into a Sybase DB. The field (image_1) is of type
"Blob". I have found two examples that I've tried, but no luck so far.
Here is what I have done:

Example 1:
strSqlImage = _
"UPDATE" & _
" table_1" & _
" SET" & _
" image_1 = ?" & _
" WHERE" & _
" id = " & ID

cmd = New OleDbCommand(strSqlImage, conn)

Dim fileStream As New System.IO.FileStream(strFilePath, IO.FileMode.Open,
IO.FileAccess.Read)
Dim b(fileStream.Length) As Byte

fileStream.Read(b, 0, b.Length)
fileStream.Close()

Dim P As New OleDbParameter("@Picture", OleDbType.VarBinary, b.Length,
Data.ParameterDirection.Input, False, 0, 0, Nothing,
Data.DataRowVersion.Current, b)
cmd.Parameters.Add(P)
conn.Open()

cmd.ExecuteNonQuery()
conn.Close()

The code gave me this error:
"[Native Error code: 1622][DataDirect ADO Sybase Provider] Type '"
Example 2:
Dim FileLength As Integer
Dim UpFile As System.Web.HttpPostedFile = txtFile.PostedFile

FileLength = UpFile.ContentLength
Dim FileByteArray(FileLength) As Byte
Dim StreamObject As System.IO.Stream = UpFile.InputStream
StreamObject.Read(FileByteArray, 0, FileLength)

strSqlImage = _
"UPDATE" & _
" table_1" & _
" SET" & _
" image_1 = ?" & _
" WHERE" & _
" id = " & ID

conn.Open()
cmd = New OleDbCommand(strSqlImage, conn)

cmd.Parameters.Add(New OleDbParameter("@Picture",
OleDbType.Binary)).Direction = System.Data.ParameterDirection.Input
cmd.Parameters("@Picture").Value = FileByteArray

cmd.ExecuteNonQuery()
conn.Close()

The code gave me this error:
"Conversion failed for command parameter[0]'@ Picture' because the data
value overflowed the type used by the provider."

I'm using "Sybase ASE OLE DB Provider" to connect to the DB. The Sybase DB
is version 11.9

I'm stuck here so please help me!

Thanks,
Shawn


Nov 18 '05 #2

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

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
2
by: Peder Y | last post by:
My code is something like this: --------------- Image img = Image.FromFile("somefile.bmp"); FileStream fStream = new FileStream("someBinaryFile.dat"); BinaryWriter bw = new...
4
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...
0
by: monfu | last post by:
Dear all I have the following code:- System.Drawing.Image src_image = System.Drawing.Image.FromStream(imgStream); Bitmap bitmap = new Bitmap(image_width, image_height,...
1
by: M Keeton | last post by:
I currently have a picture which is stored in a "System.Drawing.Image" variable and I want to save it as a bitmap file. I have tried 2 different approaches and both give me the following error: ...
5
by: TheGanjaMan | last post by:
Hi everyone, I'm trying to write up a simple image stamper application that stamps the Exif date information from the jpegs that I've taken from my digital camera and saves the new file with the...
2
by: Mark Denardo | last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage Function: What I'm trying to do is take in an image, crop off the edges around an ellipse region I set up, and then return the...
6
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)...
10
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
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.