In SQL Server, there is a data type for Image, in addition to being able to save a file, it can save a large two-bit data file, for most of the people in this column are heard but do not know how to use, today's article is going to discuss how to deposit the image into the library
Prepare for work
To reduce the length and complexity of this article, I decided to use the Upload component to complete the work on our file, using the Dundas of the money-free, please download the Dundas Upload component at the bottom of the Web site and install
Creating Data Sheets
In this case, I'm going to use the SQL library in the Pubs, please open QA and then execute the bottom of the creative data sheet instruction, the data table to be built is a content-type of the record, the other is to save a file
Create Table Imgdata
Imgid Int Identity not Null Primary Key,
ContentType VarChar (20),
HTML form Section
Now look at the part of the HTML form, because it is used as a file to use the enctype= "Multipart/form-data", but note that one but the use of form-data after the acquisition of the form can no longer use Request.Form, Because this is not the point of this article, so do not explain it more, please save the bottom of the password as insert.htm
<title> Data Library to file </title>
<form method= "POST" enctype= "Multipart/form-data" action= "insert.asp" >
<table border= "0" align= "center" >
<td><input type= "File" name= "file" size= "></td>"
<td><input type= "Submit" value= "on-line" ></td>
Stranded to see the part of the Macintosh ASP, please save the bottom of the password into insert.asp
Response.Buffer = True
ConnStr = "Provider=sqloledb;" _
& "Data source= your computer name;" _
& "Initial Catalog=pubs" _
& "User Id=sa" _
& "password= Your password"
' Build Oupload
Set oupload = Server.CreateObject ("Dundas.upload.2")
' Before using the Oupload collection (Collection), call the Save or SaveToMemory method first
Set oRs = Server.CreateObject ("Adodb.recordset")
oRS.Open "Imgdata", ConnStr, 2, 3
' Call the Oupload object ContentType, Binary, have obtained the information we want
ORs ("ContentType"). Value = oupload.files (0). ContentType
ORs ("Filedata"). Value = oupload.files (0). Binary
Set ORs = Nothing
The top program assumes you only upload one file, so use Oupload.files (0), and if you upload more than one file at a time, you can change the program to
For each ofile in Oupload.files
If InStr (1,ofile.contenttype, "image") <> 0 Then
ORs ("ContentType"). Value = Ofile.contenttype
ORs ("Imgdata"). Value = Ofile.binary
Now you can use the browser to open the insert.htm to the data library's motion, when you are done, you can Select the Imgdata data table, should be a piece of information, but Filedata should not be read!
Today's article is a first introduction to this, the next article to introduce how to pull the image from the library!
Hopefully this article will help you!