资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

图片sqlserver,图片搜索

SQLServer数据库怎么存入图片?

你可以把表的类型

在海盐等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、成都网站制作 网站设计制作定制设计,公司网站建设,企业网站建设,品牌网站建设,网络营销推广,外贸网站制作,海盐网站建设费用合理。

设计 成为二进制类型.

Binary 类型:

数据类型 描述

bit 允许 0、1 或 NULL

binary(n) 固定长度的二进制数据。最多 8,000 字节。

varbinary(n) 可变长度的二进制数据。最多 8,000 字节。

varbinary(max) 可变长度的二进制数据。最多 2GB 字节。

image 可变长度的二进制数据。最多 2GB。

不过我个人觉得,把图片 ,存到数据,会使数据库的数据,增长的很快.

不是很建议这样做.

可以把图片 存到服务器上的某个路径 下..

java如何向SQLserver库中插入图片

图片的存储有两种:

*(1)存储字符串类型的图片的地址 显示页面使用image标签

*(2)数据库有一种类型累Blok(不知道也错没)还有好多大类型,使用这个来存储

,但他存储的是2进制,在存储前先使用io读取图片,转成2进制,然后就可以存储在数据库中,

读取时也是用io

sqlserver 的图片怎么读取? 怎么存储 用asp.net 上传的

直接存,直接读.要注意格式,就是类型,数据库设计时,图片字段类型是IMAGE程序中取时转成IMAGE接收!

sql sever中照片用什么数据类型?

sql sever中照片用image数据类型。

sql sever数据库中的Image数据类型可以进行数据图片的存储。保存的是二进制字节,所以写入sql sever数据库Image数据类型时,sql sever数据库自动将图片转换成二进制字节后存入。读取的时候,将二进制再转换成图片从sql sever数据库中输出显示到页面或者程序中。

扩展资料:

如果SQL Server是缺省安装时, IMAGE类型字段是有长度限制,用来存储图片大小不超过2g的图片。缺点是占用了很大的数据存储空间。但是对于之前的存储物理路径来说读取图片和存储图片方便了很多。

一般开发中,照片等二进制的文件并不保存在数据库中。而是保存在服务器的特定目录中,然后在数据库中记录一下这个具体路径和文件名。

asp.net如何将一个图片保存到sqlserver,不是图片路径

//将图片转行为二进制的方式,存储到数据库

string name = FileUpload1.PostedFile.FileName;

string type = name.Substring(name.LastIndexOf(".") + 1); 

FileStream fs = File.OpenRead(name);

byte[] content = new byte[fs.Length];

fs.Read(content, 0, content.Length);

fs.Close();

//操作SQL数据库存储,请结合自己的软件

SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=;Persist Security Info=True;User ID=;Pooling=False;Password=");

SqlCommand cmd = conn.CreateCommand();

conn.Open();

cmd.CommandText = "insert into Images(Image_Content) values (@content)";

cmd.CommandType = CommandType.Text;

if (type == "jpg" || type == "gif" || type == "bmp" || type == "png")

{

SqlParameter para = cmd.Parameters.Add("@content", SqlDbType.Image);

para.Value = content;

cmd.ExecuteNonQuery();

}

//读取数据库字段,并展示图片

string imgid = Request.QueryString["imgid"];

SqlConnection conn1 = new SqlConnection("Data Source=;Initial Catalog=;Persist Security Info=True;User ID=sa;Pooling=False;Password=");

SqlCommand cmd1 = new SqlCommand("select Image_Content from Images where Image_ID=3", conn1);     //固定显示Image_ID为3的图片

conn1.Open();

SqlDataReader sdr = cmd1.ExecuteReader();

if (sdr.Read())

{

Response.BinaryWrite((byte[])sdr["Image_Content"]);

}

Response.End();

Sqlserver数据库存储的图片格式(二进制数据)怎么显示到页面?

1.将图片以二进制存入数据库

//保存图片到数据库

protected void Button1_Click(object sender, EventArgs e)

{

//图片路径

string strPath = "~/photo/03.JPG";

string strPhotoPath = Server.MapPath(strPath);

//读取图片

FileStream fs = new System.IO.FileStream(strPhotoPath, FileMode.Open, FileAccess.Read);

BinaryReader br = new BinaryReader(fs);

byte[] photo = br.ReadBytes((int)fs.Length);

br.Close();

fs.Close();

//存入

SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");

string strComm = " INSERT INTO personPhoto(personName, personPhotoPath, personPhoto) ";

strComm += " VALUES('wangwu', '" + strPath + "', @photoBinary )";

SqlCommand myComm = new SqlCommand(strComm, myConn);

myComm.Parameters.Add("@photoBinary", SqlDbType.Binary,photo.Length);

myComm.Parameters["@photoBinary"].Value = photo;

myConn.Open();

myComm.ExecuteNonQuery();

myConn.Close();

}

2.读取二进制图片在页面显示

//读取图片

SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");

string strComm = " SELECT personPhoto FROM personPhoto WHERE personName='wangwu' ";

SqlCommand myComm = new SqlCommand(strComm, myConn);

myConn.Open();

SqlDataReader dr = myComm.ExecuteReader();

while (dr.Read())

{

byte[] photo = (byte[])dr["personPhoto"];

this.Response.BinaryWrite(photo);

}

dr.Close();

myConn.Close();

SqlConnection myConn = new SqlConnection("Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");

SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='11' ", myConn);

DataSet myds = new DataSet();

myConn.Open();

myda.Fill(myds);

myConn.Close();

byte[] photo = (byte[])myds.Tables[0].Rows[0]["personPhoto"];

this.Response.BinaryWrite(photo);

3.设置Image控件显示从数据库中读出的二进制图片

---------------------------------------------

SqlConnection myConn = new SqlConnection("Data Source=192.168.0.1;Initial Catalog=TestDB;User ID=sa;Password=sa");

SqlDataAdapter myda = new SqlDataAdapter(" SELECT personPhoto FROM personPhoto WHERE personName='11' ", myConn);

DataSet myds = new DataSet();

myConn.Open();

myda.Fill(myds);

myConn.Close();

byte[] photo = (byte[])myds.Tables[0].Rows[0]["personPhoto"];

//图片路径

string strPath = "~/photo/wangwu.JPG";

string strPhotoPath = Server.MapPath(strPath);

//保存图片文件

BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath,FileMode.OpenOrCreate));

bw.Write(photo);

bw.Close();

3.显示图片

this.Image1.ImageUrl = strPath;

4.GridView中ImageField以URL方式显示图片

--------------------------

asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

Columns

asp:BoundField DataField="personName" HeaderText="姓名" /

asp:ImageField DataImageUrlField="personPhotoPath"

HeaderText="图片"

/asp:ImageField

/Columns

/asp:GridView

5.GridView显示读出的二进制图片

//样板列

asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound"

Columns

asp:BoundField DataField="personName" HeaderText="姓名" /

asp:ImageField DataImageUrlField="personPhotoPath"

HeaderText="图片"

/asp:ImageField

asp:TemplateField HeaderText="图片"

ItemTemplate

asp:Image ID="Image1" runat="server" /

/ItemTemplate

/asp:TemplateField

/Columns

/asp:GridView

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowIndex 0)

return;

// System.ComponentModel.Container

string strPersonName = (string)DataBinder.Eval(e.Row.DataItem, "personName");

Image tmp_Image = (Image)e.Row.Cells[2].FindControl("Image1");

if (!System.Convert.IsDBNull(DataBinder.Eval(e.Row.DataItem, "personPhoto")))

{

//

byte[] photo = (byte[])DataBinder.Eval(e.Row.DataItem, "personPhoto");

//图片路径

string strPath = "~/photo/" + strPersonName.Trim() + ".JPG";

string strPhotoPath = Server.MapPath(strPath);

//保存图片文件

BinaryWriter bw = new BinaryWriter(File.Open(strPhotoPath, FileMode.OpenOrCreate));

bw.Write(photo);

bw.Close();

//显示图片

tmp_Image.ImageUrl = strPath;

}

}


当前文章:图片sqlserver,图片搜索
当前地址:http://cdkjz.cn/article/hcsojp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220