By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,559 Members | 1,150 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,559 IT Pros & Developers. It's quick & easy.

Saving image to Sybase

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.