Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Saving image file to sql server

 
Logged in as: Guest
arrSession:exec spGetSession 2,3,153
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> ASP >> Saving image file to sql server
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Saving image file to sql server - 6/10/2001 10:41:09 PM   
  peach24

 

Posts: 7
Score: 0
Joined: 6/9/2001
From: USA
Status: offline
I try to make an asp/html page that allow user to upload file to blob
field in sql server.

please help.
 
 
Post #: 1
 
 Re: Saving image file to sql server - 6/10/2001 10:42:31 PM   
  aspprogrammer

 

Posts: 10
Score: 0
Joined: 6/9/2001
From: Belgium
Status: offline
the html would look something like:
<FORM METHOD="POST" ACTION="Sample4.asp"
ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>

But you need a component to call in Sample4.asp to process the
upload. Here's the Sample4.asp code:

<HTML>
<BODY BGCOLOR="white">

<H1>aspSmartUpload : Sample 4</H1>
<HR>

<%
' Variables
' *********
Dim mySmartUpload
Dim file
Dim oConn
Dim oRs
Dim intCount
intCount=1

' Object creation
' ***************
Set mySmartUpload =
Server.CreateObject("aspSmartUpload.SmartUpload")

' Upload
' ******
mySmartUpload.Upload

' Connect to the DB
' *****************
Set oConn = openConnection( )
'curDir = Server.MapPath("Sample.mdb")
'oConn.Open "DBQ="& curDir &";Driver={Microsoft Access
Driver (*.mdb)};DriverId=25;FIL=MS Access;"

' Open a recordset
' ****************
strSQL = "SELECT RecordID, FileName, Type, [File] FROM
tblFiles "

Set oRs = Server.CreateObject("ADODB.recordset")
'Set oRs.ActiveConnection = oConn
'oRs.Source = strSQL
oRs.LockType = 3

Call oRs.Open( strSQL, oConn, adOpenDynamic,
adLockPessimistic )

' Select each file
' ****************
For each file In mySmartUpload.Files
' Only if the file exist
' **********************
If not file.IsMissing Then

' Add the current file in a DB field
' **********************************
oRs.AddNew
file.FileToField oRs.Fields("File")
oRs("FileName") = file.FileName
oRS( "Type" ) = "tst"
oRS( "RecordID" ) = intCount
oRs.Update
intCount = intCount + 1
End If
Next

' Display the number of files uploaded
' ************************************
Response.Write(intCount & " file(s) uploaded.<BR>")

' Destruction
' ***********
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
%>
</BODY>
</HTML>


<%
function openConnection()
Dim objConnection

set objConnection =
Server.CreateObject("ADODB.Connection")
objConnection.Provider = "SQLOLEDB"
objConnection.Open "Source=dev1;UID=sa;PWD=;Initial
Catalog=bcc1-military;"

' objConnection.Open Application("ConnectionString")

set openConnection = objConnection
end function
%>
The above is a quickie but you should really use sp's to talk to the
db.

I recommend the SmartASP component only because it is free !
http://www.aspsmart.com

(in reply to peach24)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> ASP >> Saving image file to sql server Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts