如何才能往数据库里读取图片数据或者从数据库里读图片

如何才能往数据库里读取图片数据或者从数据库里读图片,第1张

给你提供个ACCESS版的VB代码,使用时调用这些过程即可:

'使用ADODB.Stream来保存/读取图像文件到数据库

'引用Microsoft ActiveX Data Objects 2.5 Library及以上版本

'保存文件到数据库中

Sub SaveFile()

Dim Stm As New ADODB.Stream

Dim Cnn As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim strCnn As String

strCnn = "Provider=Microsoft.Jet.OLEDB.4.0Persist Security Info=FalseData Source=" &_

App.Path &"\DB1.mdb"

Cnn.Open strCnn

'读取文件到内存(二进制模式)

With Stm

.Type = adTypeBinary

.Open

.LoadFromFile App.Path + "\Image1.bmp"

End With

With rs

.Open "SELECT * FROM TABLE1", Cnn, 1, 3

.AddNew

.Fields("IMAGE") = Stm.Read

.Update

End With

rs.Close

Stm.Close

Set rs = Nothing

Set Cnn = Nothing

Set Stm = Nothing

End Sub

'从数据库中读取图像文件

Sub ReadFile()

Dim Stm As New ADODB.Stream

Dim Cnn As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim strCnn As String

strCnn = "Provider=Microsoft.Jet.OLEDB.4.0Persist Security Info=FalseData Source=" &_

App.Path &"\DB1.mdb"

Cnn.Open strCnn

rs.Open "SELECT IMAGE FROM TABLE1 WHERE ID = 18", Cnn, adOpenKeyset, adLockReadOnly

'保存到文件

With Stm

.Mode = adModeReadWrite

.Type = adTypeBinary

.Open

.Write rs("IMAGE")

.SaveToFile App.Path + "\Image2.bmp"

End With

'显示图片

Picture1.Picture = LoadPicture(App.Path + "\Image2.bmp")

rs.Close

Stm.Close

Set rs = Nothing

Set Cnn = Nothing

Set Stm = Nothing

End Sub

你照这个改一下就行了:

<html><HEAD><TITLE>柳州二手网-最新产品图片信息</TITLE>

<META http-equiv=Content-Type content="text/htmlcharset=gb2312">

<STYLE type=text/css>

body,th,td{font-size:14px}

a:link {

text-decoration: nonecolor:#000000

}

a:visited {

text-decoration: nonecolor:#000000

}

a:hover {

text-decoration: nonecolor:#FF0000

}

a:active {

text-decoration: nonecolor:#FF0000

}

</STYLE>

<SCRIPT language=JavaScript>

<!-- // imgUrl

var imgUrl=new Array()

var imgLink=new Array()

var ImgTitle=new Array()

var adNum=0

//Num="20",20是指焦点图片数

imgUrl[1]="uptupian/200989125349915.jpg"

imgLink[1]="http://www.ok192.com/xinximemo.asp?cnmai=405686"

ImgTitle[1]="四季通用100%纯手编顶级汽"

imgUrl[2]="uptupian/200873135250545.jpg"

imgLink[2]="http://www.ok192.com/xinximemo.asp?cnmai=211010"

ImgTitle[2]="投影幕布等全套投影设备出租"

imgUrl[3]="uptupian/20099591415626.jpg"

imgLink[3]="http://www.ok192.com/xinximemo.asp?cnmai=401042"

ImgTitle[3]="最新版蓝光雷柏无线鼠标 10"

imgUrl[4]="uptupian/200941172350436.jpg"

imgLink[4]="http://www.ok192.com/xinximemo.asp?cnmai=367590"

ImgTitle[4]="传统硬朗男性形象-HUGO "

imgUrl[5]="uptupian/200994132922742.jpg"

imgLink[5]="http://www.ok192.com/xinximemo.asp?cnmai=413173"

ImgTitle[5]="【行货】性能超过IBMT41"

imgUrl[6]="uptupian/200995125552861.jpg"

imgLink[6]="http://www.ok192.com/xinximemo.asp?cnmai=413214"

ImgTitle[6]="电脑全套低价出售"

imgUrl[7]="uptupian/20081024171548501.jpg"

imgLink[7]="http://www.ok192.com/xinximemo.asp?cnmai=335858"

ImgTitle[7]="送礼佳品-工艺品壁画挂画字画"

imgUrl[8]="uptupian/20095304443130.jpg"

imgLink[8]="http://www.ok192.com/xinximemo.asp?cnmai=376058"

ImgTitle[8]="AIR MAX 2009耐克"

imgUrl[9]="uptupian/200995105533886.jpg"

imgLink[9]="http://www.ok192.com/xinximemo.asp?cnmai=413383"

ImgTitle[9]="中国驰名商标高得乐太阳能下乡"

imgUrl[10]="uptupian/200982716176349.jpg"

imgLink[10]="http://www.ok192.com/xinximemo.asp?cnmai=410947"

ImgTitle[10]="550元卖台9.5成新摩托罗"

imgUrl[11]="uptupian/2009623104533555.jpg"

imgLink[11]="http://www.ok192.com/xinximemo.asp?cnmai=387163"

ImgTitle[11]="专办C1证:一个月得证荣驾教"

imgUrl[12]="uptupian/20096591630438.jpg"

imgLink[12]="http://www.ok192.com/xinximemo.asp?cnmai=385468"

ImgTitle[12]="09年最新潮时尚火柴式打火机"

imgUrl[13]="uptupian/20099422450391.jpg"

imgLink[13]="http://www.ok192.com/xinximemo.asp?cnmai=413284"

ImgTitle[13]="联想p2.6自用主机"

imgUrl[14]="uptupian/200995115932922.jpg"

imgLink[14]="http://www.ok192.com/xinximemo.asp?cnmai=413401"

ImgTitle[14]="IBM商务笔记本电脑,700"

imgUrl[15]="uptupian/200995121744229.jpg"

imgLink[15]="http://www.ok192.com/xinximemo.asp?cnmai=413405"

ImgTitle[15]="桌球台,桌球台厂家,深圳桌球"

imgUrl[16]="uptupian/20099413410614.jpg"

imgLink[16]="http://www.ok192.com/xinximemo.asp?cnmai=413177"

ImgTitle[16]="【性价比无敌】戴尔D600笔"

imgUrl[17]="uptupian/2009614233616131.gif"

imgLink[17]="http://www.ok192.com/xinximemo.asp?cnmai=388340"

ImgTitle[17]="催眠安睡小乌龟星空灯"

imgUrl[18]="uptupian/2009829143838248.jpg"

imgLink[18]="http://www.ok192.com/xinximemo.asp?cnmai=410070"

ImgTitle[18]="(赠送)汽车前挡免撕标志贴"

imgUrl[19]="uptupian/2009312142439300.jpg"

imgLink[19]="http://www.ok192.com/xinximemo.asp?cnmai=362140"

ImgTitle[19]="车用夏季遮阳挡套装组合(前后"

imgUrl[20]="uptupian/200995115111445.jpg"

imgLink[20]="http://www.ok192.com/xinximemo.asp?cnmai=413400"

ImgTitle[20]="代理销售比特梵德杀毒软件"

function setTransition(){

if (document.all){

imgUrlrotator.filters.revealTrans.Transition=Math.floor(Math.random()*23)

imgUrlrotator.filters.revealTrans.apply()

}

}

function playTransition(){

if (document.all)

imgUrlrotator.filters.revealTrans.play()

}

function nextAd(){

//adNum<8,8是指焦点图片数

// alert("000")

if(adNum<20)adNum++

else adNum=1

setTransition()

document.images.imgUrlrotator.src=imgUrl[adNum]

document.all.tags("div")[0].innerText=ImgTitle[adNum]

playTransition()

theTimer=setTimeout("nextAd()", 8000)

}

function jump2url(){

jumpUrl=imgLink[adNum]

jumpTarget='_blank'

if (jumpUrl != ''){

if (jumpTarget != '')window.open(jumpUrl,jumpTarget)

else location.href=jumpUrl

}

}

function displayStatusMsg() {

status=imgLink[adNum]

document.returnValue = true

}

//-->

</SCRIPT>

</HEAD>

<BODY><A onmouseover="displayStatusMsg()return document.returnValue" href="javascript:jump2url()"><IMG style="FILTER: revealTrans(duration=2,transition=20)" height=173 src="uptupian/20099591415626.jpg" width=187 border=0 name=imgUrlrotator>

<DIV style="WIDTH: 187pxCURSOR: handLINE-HEIGHT: 35pxBACKGROUND-COLOR: #ffffffTEXT-ALIGN: centertext-valign: middle">最新版蓝光雷柏无线鼠标 10</DIV></A>

<SCRIPT language=JavaScript>nextAd()</SCRIPT>

</BODY></html>

首先说你的这种方法不好。现在的读取图片的方式都是在服务器端建立个用于存储图片的文件夹,里面存图片。然后数据库里面保存的都是这个图片的地址。读图片的时候只需要用<img src='<%# aaa %>'>这种读地址的方式就可以了。你说的那种直接存的方法,占用资源大,而且性能不好。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/9807167.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-02
下一篇2023-05-02

发表评论

登录后才能评论

评论列表(0条)

    保存