Help with inserting BLOB
389219Mar 4 2003 — edited Mar 6 2003Hi All...
I'm new to Oracle, and also to ODP.NET, so please forgive my newbieness.
I have revieed the sample code for inserting/updating a BLOB into an oracle database, but am still confused, so I'm hoping for a simple code sample to get me started.
I am loading an image into a filestream, enumerating through the stream and reading bytes. I am able append each byte and concatenate them into a string, however, I need to get them back into a format I can insert into an existing blob column (currently null). The examples I see require first selecting the row with the blob, then updating the indexed column value with the new blob data.
2 questions...
Is there a way to simply insert a blob, ie
"Insert into table (blob_test) values (blob)"
and
How do I either assign either the value of fs (below is the code) to a blob OR convert the string s to a blob and insert it? I'm working in VB.NET.
Again, sorry for the elementary nature of my question.
Code below:
Regards,
Doug Oliver
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim fs As New System.IO.FileStream("C:\Inetpub\wwwroot\pagerror.gif", IO.FileMode.Open, IO.FileAccess.Read)
Dim s As String
For i = 0 To fs.Length
s = s & fs.ReadByte()
Next
Dim strSQL = "Insert into towns (TOWN_NAME,DIST_OFF,SCHL_DISTRICT_TXT,TOWN_CDE,COUNTY_CDE,DO_CDE,test_blob) VALUES ('TestTownDoug','TestOfficeDoug','TestSchoolDistDoug',6666,7777,8888,s)"
'DISPLAYING THE IMAGE FROM STREAM IS SUCCESSFUL
Me.PictureBox1.Image = Image.FromStream(fs)
Me.PictureBox1.Show()
fs.Close()
GetTowns(strSQL)
End Sub
Public Function GetTowns(ByVal strSQL As String) As String
Dim objConnection As OracleConnection = New OracleConnection("User ID=doliver; Password=nash2003; Data Source=nhbvrd")
Dim objDataAdapter As OracleDataAdapter = New OracleDataAdapter()
Dim cmd As OracleCommand = New OracleCommand()
objConnection.Open()
cmd.Connection = objConnection
cmd.CommandText = strSQL
'I GET THE INSERT ERROR HERE AT CMD.EXECUTENONQUERY()
cmd.ExecuteNonQuery()
GetTowns = "DONE"
cmd.Dispose()
objConnection.Close()
objDataAdapter.Dispose()
objConnection.Dispose()
End Function