上传图片


<input id="UpPhoto" name="UpPhoto" runat="server" type="file">
<asp:Button id="btnAdd" name="btnAdd" runat="server" Text="上传"
onclick="btnAdd_Click"></asp:Button>



string connstr = @"Data Source=WANGRUI-PC\WANGRUI;Initial Catalog=JingDong;Persist Security Info=True;User ID=sa;Password=admin";
using (SqlConnection conn = new SqlConnection(connstr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
//获得图象并把图象转换为byte[]
HttpPostedFile upPhoto = UpPhoto.PostedFile;
int upPhotoLength = upPhoto.ContentLength;
byte[] PhotoArray = new Byte[upPhotoLength];
Stream PhotoStream = upPhoto.InputStream;
PhotoStream.Read(PhotoArray, 0, upPhotoLength);
cmd.CommandText = "insert into eBookxinxi(eBimg,eBmimg,eBtj,eBnjj,eBzjj,eBml,eBname,sjid,eBzz,eBjg) values (@FImage,@image,@tj,@njj,@zjj,@ml,@name,@id,@zz,@jg)";
cmd.Parameters.Add("@FImage", SqlDbType.Image);
cmd.Parameters["@FImage"].Value = PhotoArray;

p'

建一个图片网页
if (!Page.IsPostBack)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=WANGRUI-PC\\WANGRUI;Database=JingDong;User Id=sa;Pwd=admin";
string strSql = "select * from eBookxinxi where eBid=1";//这里假设获取id为2的图片
SqlCommand cmd = new SqlCommand(strSql, conn);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
Response.ContentType = "application/octet-stream";
Response.BinaryWrite((Byte[])reader["eBimg"]);
Response.End();
reader.Close();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值