62,046
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Drawing;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=test;User ID=sa;Password=123456");
con.Open();
SqlDataAdapter ada = new SqlDataAdapter("select * from tb14", con);
DataSet ds = new DataSet();
ada.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "id";
DropDownList1.DataValueField = "id";
DropDownList1.DataBind();
Image1.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Image1.Visible = true;
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=test;User ID=sa;Password=123456");
string imagename = "";
try
{
con.Open();
SqlCommand com = new SqlCommand("select * from tb14 where id=" + DropDownList1.Text + "", con);
SqlDataReader dr = com.ExecuteReader();
dr.Read();
MemoryStream ms = new MemoryStream((Byte[])dr["tName"]);
Bitmap image = new Bitmap(ms);
string filepath = Server.MapPath("Img/");
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 = "Img/" + ((i + 1) + ".jpg");
}
finally
{
con.Close();
}
}
}