Asp.net(c#)将数据库中以二进制存的图片显示出来
2010-04-08 14:13
841 查看
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;database=库名");
SqlDataAdapter ada = new SqlDataAdapter("select * from tb_17 ", con);
con.Open();
DataSet ds = new DataSet();
ada.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "字段";
DropDownList1.DataValueField = "字段";
DropDownList1.DataBind();
Image1.Visible=false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Image1.Visible = true;
SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;database=库名");
string imagename = "";
try
{
con.Open();
SqlCommand com = new SqlCommand("select name from 表名 where 字段="+DropDownList1.Text+"", con);
SqlDataReader dr = com.ExecuteReader();
dr.Read();
MemoryStream ms = new MemoryStream((Byte[])dr["name"]);
Bitmap image = new Bitmap(ms);
string filepath = Server.MapPath("Files/");
DirectoryInfo dir = new DirectoryInfo(filepath);
FileInfo[] filecount = dir.GetFiles();
int i = filecount.Length;
imagename = filepath + ((i + 1) + ".jpg");
image.Save(imagename);
dr.Close();
Image1.ImageUrl = "Files/" + ((i + 1) + ".jpg");
}
finally
{
con.Close();
}
}
}
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;database=库名");
SqlDataAdapter ada = new SqlDataAdapter("select * from tb_17 ", con);
con.Open();
DataSet ds = new DataSet();
ada.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "字段";
DropDownList1.DataValueField = "字段";
DropDownList1.DataBind();
Image1.Visible=false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Image1.Visible = true;
SqlConnection con = new SqlConnection("server=(local);user id=sa;pwd=;database=库名");
string imagename = "";
try
{
con.Open();
SqlCommand com = new SqlCommand("select name from 表名 where 字段="+DropDownList1.Text+"", con);
SqlDataReader dr = com.ExecuteReader();
dr.Read();
MemoryStream ms = new MemoryStream((Byte[])dr["name"]);
Bitmap image = new Bitmap(ms);
string filepath = Server.MapPath("Files/");
DirectoryInfo dir = new DirectoryInfo(filepath);
FileInfo[] filecount = dir.GetFiles();
int i = filecount.Length;
imagename = filepath + ((i + 1) + ".jpg");
image.Save(imagename);
dr.Close();
Image1.ImageUrl = "Files/" + ((i + 1) + ".jpg");
}
finally
{
con.Close();
}
}
}
相关文章推荐
- Asp.net(c#)将数据库中以二进制存的图片显示出来
- asp.net FileUpload 控件上传文件 以二进制的形式存入数据库并将图片显示出来
- ASP.NET(C#) 实现将图片以二进制保存到数据库中
- Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
- ASP.net:上传图片以二进制插入到数据库,且读取显示
- asp.net(c#)从数据库里读取图片并显示到页面
- Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
- asp.net(c#)从数据库里读取图片并显示到页面
- ASP.NET(C#) 实现将图片以二进制保存到数据库中 转
- ASP.net(c#)将图片以二进制格式存储到数据库中
- Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
- Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
- C# 用二进制将图片保存在数据库里再读出来显示在pictureBox中
- ASP.net(c#)将图片以二进制格式存储到数据库中
- Asp.net 2.0(C#)图片存储到数据库和从数据库读取显示
- C#从数据库中读取二进制数据,并显示图片
- C#将相片转换成二进制存储在数据库中,再从数据库中显示出来
- 在ASP.NET中自动合并小图片并使用CSS Sprite显示出来
- asp.net ,c# 保存图片入数据库
- 将图片插入数据库并使用asp.net读取出来的正确方法