网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

sqlserver是图片,sqlserver图片字段

SQLServer数据库怎么存入图片?

你可以把表的类型

成都创新互联是专业的涞源网站建设公司,涞源接单;提供成都网站制作、做网站,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行涞源网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

设计 成为二进制类型.

Binary 类型:

数据类型 描述

bit 允许 0、1 或 NULL

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

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

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

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

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

不是很建议这样做.

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

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

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

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

扩展资料:

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

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

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 的图片怎么读取? 怎么存储 用asp.net 上传的

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

如何在sql server中存储图片

1、首先可以存储图片链接,设置图片链接字段,如下图所示。

2、接着直接将图片的链接添加到SQL数据表的字段里即可,如下图所示。

3、或者用二进制存储图片字段,在SQL Server数据库中先制作成image字段。

4、接着在后台通过代码形式,将图片转化为二进制,如下图所示。

5、得到二进制数据后,则可通过sql语句插入到数据表中。

6、数据表即可存储了图片字段,将二进制转化为图片。


本文名称:sqlserver是图片,sqlserver图片字段
网站地址:http://bjjierui.cn/article/dscossp.html

其他资讯