mack1er
asked on
Bianary INSERT!!!
Hello all,
I have to insert a binary file along with user entered data from a form into a SQL db. I HAVE to use an insert statement, I cannot use rs.Addnew like all the rest of the crud I've found on the web says. I am not able to use the aapendchunk statement the way I would like to. I would like to use rs("FileData").AppendChunk = fileData but I cannot, I NEED to use an insert statement... The field name is FileData, my variable to handle the file is called file data.
Here is my SQL statement:
sql = "INSERT INTO Files (companyname, filetype, filesubcategory, filename, filesize, keywords, filedata, filecontent)
VALUES
('"&companynameInput2&"', '"&filetype&"', '"&filesubcategory&"', '"&fileName&"', '"&fileSize&"', '"&keywords&"', '"&fileData&"', '"&contentType&"')"
Any ideas???
I have to insert a binary file along with user entered data from a form into a SQL db. I HAVE to use an insert statement, I cannot use rs.Addnew like all the rest of the crud I've found on the web says. I am not able to use the aapendchunk statement the way I would like to. I would like to use rs("FileData").AppendChunk
Here is my SQL statement:
sql = "INSERT INTO Files (companyname, filetype, filesubcategory, filename, filesize, keywords, filedata, filecontent)
VALUES
('"&companynameInput2&"', '"&filetype&"', '"&filesubcategory&"', '"&fileName&"', '"&fileSize&"', '"&keywords&"', '"&fileData&"', '"&contentType&"')"
Any ideas???
You really can't do it that simply....Can you create a stored proc--you can pass the binary type to the proc and basically do a simple insert that way.....
ASKER
I have access to the server and could create one, I just don't know about the code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nope, sorry that won't work. I keep getting:
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
Can't use rs.addnew. Here is how I connect to my db (using a com object):
<!-- METADATA TYPE="TypeLib" UUID="{00000205-0000-0010- 8000-00AA0 06D2EA4}" -->
<%
' Open database connection
set objConn = CreateObject("Shared.Datab ase")
set cmdText = objConn.Connect("documents ")
%>
<%
Dim rs
dim sql
sql= "files"
Set rs = Server.CreateObject("ADODB .Recordset ")
cmdText.CommandText = sql
rs.open cmdtext
%>
Addnew here bombs...
ANY IDEAS?????????
ADODB.Recordset error '800a0e78'
Operation is not allowed when the object is closed.
Can't use rs.addnew. Here is how I connect to my db (using a com object):
<!-- METADATA TYPE="TypeLib" UUID="{00000205-0000-0010-
<%
' Open database connection
set objConn = CreateObject("Shared.Datab
set cmdText = objConn.Connect("documents
%>
<%
Dim rs
dim sql
sql= "files"
Set rs = Server.CreateObject("ADODB
cmdText.CommandText = sql
rs.open cmdtext
%>
Addnew here bombs...
ANY IDEAS?????????
Is your com object just for connectivity to the database or does it provide a full range of methods for SQL data manipulation?
This is the syntax for calling a proc with a blob:
strSPName = "dbo.Mydatabase.Update_Use rs"
With cmdSQLServer
.Connection = cnSQLServer
.CommandText = strSPName
.CommandType = CommandType.StoredProcedur e
End With
prmSQLParameter = cmdSQLServer.Parameters.Ad d
("@pkuserid", txtPKUserID.Text)
prmSQLParameter = cmdSQLServer.Parameters.Ad d
("@firstname", txtFirstName.Text)
prmSQLParameter = cmdSQLServer.Parameters.Ad d
("@middlename", txtMiddleName.Text)
prmSQLParameter =
cmdSQLServer.Parameters.Ad d("@Photo" , SqlDbType.Binary, aUserImage)
strSPName = "dbo.Mydatabase.Update_Use
With cmdSQLServer
.Connection = cnSQLServer
.CommandText = strSPName
.CommandType = CommandType.StoredProcedur
End With
prmSQLParameter = cmdSQLServer.Parameters.Ad
("@pkuserid", txtPKUserID.Text)
prmSQLParameter = cmdSQLServer.Parameters.Ad
("@firstname", txtFirstName.Text)
prmSQLParameter = cmdSQLServer.Parameters.Ad
("@middlename", txtMiddleName.Text)
prmSQLParameter =
cmdSQLServer.Parameters.Ad
ASKER
The com object allows for connection to the db and using it i have been able to select, insert, and delete so far. Just no luck with the binary file.