PDA

View Full Version : Insert Binary into DB?



Morgoth
Jul 7th, 2002, 02:48 AM
How do I send a binary picture into a database If I already have the binary that needs to be inserted?

File.Binary = The picture I have, already in binary form.


Why do I get the error "Type mismatch" when I try:

oConn = Connectiong to DB

Strimage = File.Binary

sSQL = "INSERT INTO images (image) VALUES (" & Strimage & ")"

Set oRS = oConn.Execute(sSQL)

...?

whammy
Jul 7th, 2002, 03:10 AM
I've never inserted binary data into a db... but have you tried it as a string (just guessing here)?

sSQL = "INSERT INTO images (image) VALUES ('" & Strimage & "')"

oracleguy
Jul 7th, 2002, 08:28 AM
Just a shot in the dark:



http://www.google.com/search?hl=en&q=%22SQL%22+Inserting+binary+picture+via+ASP+NOT+VB6


Look here.

I personally haven't done it otherwise I'd be more helpful.

Morgoth
Jul 7th, 2002, 10:17 AM
Whammy, that doesn't matter, I don't think. It doesn't change anything though... Maybe you could acually explan to me the differance in the two ways? '" & str & "' over " & Str & " for inserting into a database even with normal strings...



Oracleguy, first off...

http://www.google.com/search?hl=en&lr=&ie=ISO-8859-1&q=Inserting+binary+picture+via+ASP+NOT+VB6&btnG=Google+Search

...is the link your's got cut because of some script this forum has. It turns some of the text into "...". Also I would rather use a forum then do a search because the result in a search might not beable to get the type of code I am looking for with what specifications i am looking for, plus i already looked, and found nothing. (I would rather use a forum :) )


I think I can do anyother way, but I don't know exactly how to do it. I am taking this from an old uploader that doesn't use a component.



Dim RS,Con,Cstring,sql,MYMESSAGE,i,j
CString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/db/images.mdb")
Set CON = server.CreateObject("adodb.connection")
Con.open Cstring
Set RS = Server.CreateObject("ADODB.Recordset")
SQL= "SELECT filename, filesize, contenttype, filedata, fullname, EMAIL, story, t from my"
RS.Open SQL,con,2,3
RS.AddNew
RS("filename") = File.FileName
RS("filesize") = File.FileSize
RS("contenttype") = Request.servervariables("remote_addr")
RS("FULLNAME") = Uploader.Form("fullname")
RS("EMAIL") = Uploader.Form("EMAIL")
RS("story") = Uploader.Form("story")
RS("t") = DATE
' Save the file to the database
File.SaveToDatabase RS("filedata")
' Commit the changes and close
RS.Update
RS.Close


I am gunna mess around with that now. If you can help, see what you can do too.

Thank you, Whammy, Oracleguy.

Morgoth
Jul 7th, 2002, 11:08 AM
I don't get it!!!!
I went into the options for the databse folder and set Web Sharing to share this folder, at the begining. nothing happend.
I turned it off just now, and I went to security and added in "Everyone" and it worked... maybe with the old code, but I used the new code.



Dim oConn, strconn, RS, sSQL
Set oConn = server.CreateObject("ADODB.Connection")
strconn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/images.mdb") & ";"
oConn.open strconn
Set RS = Server.CreateObject("ADODB.Recordset")
sSQL = "SELECT image FROM images"
RS.Open sSQL,strconn,2,3
RS.AddNew
RS("image") = File.Binary
RS.Update
RS.Close