社区
ASP
帖子详情
在SQL SERVER中如何存储图片,并可以显示
chuting1
2007-01-28 02:09:36
产品说明里有图片,SQL SERVER里设置有image类型的字段来存储,如果做
写入后,如果显示出来
...全文
2431
14
打赏
收藏
在SQL SERVER中如何存储图片,并可以显示
产品说明里有图片,SQL SERVER里设置有image类型的字段来存储,如果做 写入后,如果显示出来
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
14 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
cow8063
2007-01-29
打赏
举报
回复
or
<img src="inc/product_showimg.asp?product_id=<%=(rs.Fields.Item("product_id").Value)%>" >
'***********************
'
product_showimg.asp
'***********************
<%
Response.Buffer = True
Response.Expires = 0
Response.Clear
Response.ContentType = "image/gif"
%>
<%
set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = MM_conn_STRING
rs.Source = "SELECT product_smallpic FROM products WHERE product_id = " & Request("product_id")
rs.CursorType = 1
rs.CursorLocation = 2
rs.LockType = 3
rs.Open()
s = rs("product_smallpic").ActualSize
data = rs("product_smallpic").GetChunk(s)
Response.BinaryWrite data
%>
<%
rs.Close()
%>
cow8063
2007-01-29
打赏
举报
回复
<%
'<!--#include file="adovbs.inc"-->
Dim oConn
Dim oRs
Dim Pic
Dim PicSize
sqlstr=Request.QueryString("sqlstr")
Response.Buffer = TRUE
Response.ContentType = "image/gif"
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open session("filedsn")
' Query SQL to obtain recordset containing gif BLOB
Set oRs = oConn.Execute(sqlstr)
'
' Obtain local variable of GIF
PicSize = oRs("color").ActualSize
Pic = oRs("color").GetChunk(PicSize)
Response.BinaryWrite Pic
Response.End
%>
Webmagic
2007-01-29
打赏
举报
回复
思路是用上传组件,上传图片,传的时候将图片的名字或保存的路径写到sqlserver的一个pic字段里(类型为varchar),前面显示时用<img src=rs("pic")>显示即可,注意路径。。
chuting1
2007-01-29
打赏
举报
回复
本人用的是ASP,不是ASP.NET
chuting1
2007-01-29
打赏
举报
回复
楼上的,有点看不懂
chenguang79
2007-01-29
打赏
举报
回复
在SQL中存储图片一般采用二进制方法。这种方法不太容易检查数据是否正常。而且存储起来比较麻烦,楼主为什么不用常用的方法,只把图片的地址存入数据库,而把图片放到一个文件夹里呢。这样容易检查数据库的正确性,而且操作也比较方便
mh_rock
2007-01-29
打赏
举报
回复
在SQL Server中保存和输出图片
介绍
有时候我们需要保存一些binary data进数据库。SQL Server提供一个叫做image的特殊数据类型供我们保存binary data。Binary data可以是图片、文档等。在这篇文章中我们将看到如何在SQL Server中保存和输出图片。
建表
为了试验这个例子你需要一个含有数据的table(你可以在现在的库中创建它,也可以创建一个新的数据库),下面是它的结构:
Column Name
Datatype
Purpose
ID
Integer
identity column Primary key
IMGTITLE
Varchar(50)
Stores some user friendly title to identity the image
IMGTYPE
Varchar(50)
Stores image content type. This will be same as recognized content types of ASP.NET
IMGDATA
Image
Stores actual image or binary data.
保存images进SQL Server数据库
为了保存图片到table你首先得从客户端上传它们到你的web服务器。你可以创建一个web form,用TextBox得到图片的标题,用HTML File Server Control得到图片文件。确信你设定了Form的encType属性为multipart/form-data。
Stream imgdatastream = File1.PostedFile.InputStream;
int imgdatalen = File1.PostedFile.ContentLength;
string imgtype = File1.PostedFile.ContentType;
string imgtitle = TextBox1.Text;
byte[] imgdata = new byte[imgdatalen];
int n = imgdatastream.Read(imgdata,0,imgdatalen);
string connstr=
((NameValueCollection)Context.GetConfig
("appSettings"))["connstr"];
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand
("INSERT INTO ImageStore(imgtitle,imgtype,imgdata)
VALUES ( @imgtitle, @imgtype,@imgdata )", connection );
SqlParameter paramTitle = new SqlParameter
("@imgtitle", SqlDbType.VarChar,50 );
paramTitle.Value = imgtitle;
command.Parameters.Add( paramTitle);
SqlParameter paramData = new SqlParameter
( "@imgdata", SqlDbType.Image );
paramData.Value = imgdata;
command.Parameters.Add( paramData );
SqlParameter paramType = new SqlParameter
( "@imgtype", SqlDbType.VarChar,50 );
paramType.Value = imgtype;
command.Parameters.Add( paramType );
connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();
从数据库中输出图片
现在让我们从数据库中取出我们刚刚保存的图片,在这儿,我们将直接将图片输出至浏览器。你也可以将它保存为一个文件或做任何你想做的。
private void Page_Load(object sender, System.EventArgs e)
{
string imgid =Request.QueryString["imgid"];
string connstr=((NameValueCollection)
Context.GetConfig("appSettings"))["connstr"];
string sql="SELECT imgdata, imgtype FROM ImageStore WHERE id = "
+ imgid;
SqlConnection connection = new SqlConnection(connstr);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
SqlDataReader dr = command.ExecuteReader();
if(dr.Read())
{
Response.ContentType = dr["imgtype"].ToString();
Response.BinaryWrite( (byte[]) dr["imgdata"] );
}
connection.Close();
}
在上面的代码中我们使用了一个已经打开的数据库,通过datareader选择images。接着用Response.BinaryWrite代替Response.Write来显示image文件。
chuting1
2007-01-29
打赏
举报
回复
多谢各位
已经解决
<!-- #include file = "path.asp"-->
<%
set con=conn
set rec=server.createobject("ADODB.recordset")
'response.write request("id")
strsql="select tp from dimg where id="&request("id")&""
rec.open strsql,con,1,1
Response.ContentType = "image/*"
picsize=rec("tp").ActualSize
Response.BinaryWrite rec("tp").getChunk(picsize)
rec.close
set rec=nothing
response.end
%>
kele1006
2007-01-29
打赏
举报
回复
建议你直接用上传组件来做
自己写有点麻烦=.=
chuting1
2007-01-29
打赏
举报
回复
TO cloudgamer(欢迎交流qq215754452) (
又是如何显示存储的图片呢
cloudgamer
2007-01-28
打赏
举报
回复
<!--#include virtual="/_inc/conn.inc"-->
<%
'取得客户端送出的数据字节大小
frmsize=Request.TotalBytes
'以二进制方式读取数据
frmData=Request.BinaryRead(frmsize)
'去掉实际数据前、后的边界字符串行
bnCrLf=ChrB(13)&ChrB(10)
divider=leftB(frmdata,CLng(InstrB(frmdata,bnCrLf))-1)
dataStart=InstrB(frmData,bnCrLf&bncrlf)+4
dataEnd=InstrB(datastart+1,frmData,divider)-dataStart
'读出图象数据
myData=Midb(frmdata,dataStart,dataEnd)
'将图象数据存入数据库
strSQL="SELECT * FROM tblImages"
set rs=Server.CreateObject("ADODB.Recordset")
rs.open strSQL,conn,1,3
rs.addnew
rs("picData").AppendChunk myData
rs.Update
counts=rs.recordCount+1
rs.close
conn.close
%>
sib2000
2007-01-28
打赏
举报
回复
很少人直接把图片存在数据库里的,数据库里的images只是个中继,最后会读出后写入到服务器生成文件。再在产品表里将图片的名字写入。直接使用url形式显示图片,非直接从数据库读取。
「已注销」
2007-01-28
打赏
举报
回复
up
websterjt
2007-01-28
打赏
举报
回复
用上传组件,上传图片,然后取得图片路径存入image字段中!以后再前台调用的时候读取就可以了!
asp.net
存储
图片
到
sql
server
数据库并
显示
asp.net
存储
图片
到
sql
server
数据库并
显示
收藏 使用ASP.NET实现将
图片
存储
到
SQL
server
数据库
中
UploadImage.aspx文件 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> http://www.w3.org/1999/xhtml" > 无标题页 上传
图片
(选
[网络收集]asp.net
存储
图片
到
sql
server
数据库并
显示
UploadImage.aspx文件 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadImage.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http...
sql
server
存储
图片
本文总结如何在.Net WinForm和.Net WebForm(asp.net)
中
将
图片
存入
SQL
Server
中
并读取
显示
的方法 。 1.使用asp.net将
图片
上传并存入
SQL
Server
中
,然后从
SQL
Server
中
读取并
显示
出来: 1)上传并存入
SQL
Server
数据库结构 create table test { id identity(1,1), FIm
怎样上传
图片
,把
图片
保存到
sql
server
数据库里
先在
SQL
Server
中
建立一个
图片
存储
的数库表,ImageData Column为图象二进制数据储存字段,ImageContentType Column为图象文件类型记录字段,ImageDescription Column为储蓄图象文件说明字段,ImageSize Column为储存图象文件长度字段,结构如下: CREATE TABLE [dbo].[ImageStore]
c#
图片
保存到数据库和从数据库读取
图片
并
显示
C#
图片
保存到数据库和从数据库读取
图片
并
显示
关键字: c#
图片
保存到数据库和从数据库读取
图片
并
显示
图片
保存到数据库的方法:
public void imgToDB(string
sql
)
{ //参数
sql
中
要求保存的imge变量名称为@images
//调用方法如:imgToDB("update UserPhoto set Photo=@images where UserNo='" +
ASP
28,403
社区成员
356,942
社区内容
发帖
与我相关
我的任务
ASP
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
复制链接
扫一扫
分享
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章