Saving image to Sybase

S

Shawn

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
 
S

Shawn

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


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top