Blob
I'm using VB.Net 2005 and oracle 10g
I need to save an image at the field "BACKGROUND_IMAGE" on the table GS_USERS; so I wrote the code:
Dim conn As New OleDbConnection
Dim cmd As New OleDbCommand
Dim SQL As String
Dim FileSize As UInt32
Dim rawData() As Byte
Dim fs As FileStream
conn.ConnectionString = My.Settings.CPMSConnectionString
Try
fs = New FileStream(FileName, FileMode.Open, FileAccess.Read)
FileSize = fs.Length
rawData = New Byte(FileSize) {}
If rawData.Length / (1024 * 1024) > 1 Then '1MB
MessageBox.Show("Image so big.Please choose another one", "", MessageBoxButtons.OK, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1)
Exit Sub
End If
fs.Read(rawData, 0, FileSize)
fs.Close()
conn.Open()
'SQL = "INSERT INTO file VALUES(NULL, ?FileName, ?FileSize, ?File)"
SQL = "UPDATE GS_USERS SET BACKGROUND_IMAGE=?File WHERE ID_USER=1 AND ID_COMPANY=1 AND ID_BRANCH=2"
cmd.Connection = conn
cmd.CommandText = SQL
'cmd.Parameters.Add("?FileName", strFileName)
'cmd.Parameters.Add("?FileSize", FileSize)
Dim PARAM As New OleDbParameter("?File", OleDbType.Binary)
PARAM.Value = rawData
PARAM = cmd.Parameters.Add(PARAM) '("?File", OleDbType.VarBinary, rawData.Length)
cmd.ExecuteNonQuery()
MessageBox.Show("File Inserted into database successfully!", _
"Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
conn.Close()
Catch ex As Exception
MessageBox.Show("There was an error: " & ex.Message, "Error", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Note that My.Settings.CPMSConnectionString is
'Provider=MSDAORA;Data Source=CPMS;Persist Security Info=True;Password=nagham;User ID=nagham
It gave me the exception:
'MSDAORA' failed with no error message available, result code: E_FAIL(0x80004005).
Any Help ?

