将图片保存到数据库并用GridView显示
来源:互联网 发布:淘宝如何延长付款 编辑:程序博客网 时间:2024/05/20 06:27
int len = Upload.PostedFile.ContentLength;
byte[] pic = new byte[len];
Upload.PostedFile.InputStream.Read(pic, 0, len);// 插入图片和说明到数据库中
ashx读取上传至数据库中的图片
public class GetImage : IHttpHandler {
public bool IsReusable{
get {
return true;
}
}
public void ProcessRequest(HttpContext context){
// Set up the response settings
context.Response.ContentType = "image/jpg";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;
string photoId ="";
Stream stream = null;
if (context.Request.QueryString["kp_item_no"] != null &&
context.Request.QueryString["kp_item_no"] != "") {
photoId = context.Request.QueryString["kp_item_no"].ToString ();
stream = GetPhoto(photoId);
}
const int buffersize = 1024 * 16;
byte[] buffer = new byte[buffersize];
int count = stream.Read(buffer, 0, buffersize);
while (count > 0) {
context.Response.OutputStream.Write(buffer, 0, count);
count = stream.Read(buffer, 0, buffersize);
}
context.Response.End();
}
public Stream GetPhoto(string photoId)
{
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["mydbConnectionString"].ConnectionString);
SqlCommand myCommand = new SqlCommand
("SELECT cast(isnull([goods_picture],'0')as image ) FROM [jb_spzl_image] WHERE [kp_item_no]=@PhotoID ",
myConnection);
myConnection.Open();
myCommand.CommandType = System.Data.CommandType.Text;
// myCommand.Parameters.Add(new SqlParameter("@PhotoID", photoId));
myCommand.Parameters.AddWithValue("@PhotoID", photoId);
object result = myCommand.ExecuteScalar();
try
{
return new MemoryStream((byte[])result);
}
catch (ArgumentNullException e)
{
return null;
}
finally
{
myConnection.Close();
}
}
}
- 将图片保存到数据库并用GridView显示
- 如何将TextBox数据提交到GridView显示再保存到数据库
- 将图片保存到数据库表中及从数据库表中读取图片并显示
- c#读取数据库中图片路径,将图片保存到imagelist,在listview显示
- 将图片保存到ORACEL数据库和读取数据显示到页面
- 将图片保存到数据库中
- 将图片保存到数据库的处理
- VC++ 将图片保存到数据库
- android 将图片保存到数据库
- 将图片保存到SQL数据库中
- 如何将图片保存到sql数据库
- jdbc将图片保存到数据库
- 如何将pictureBox里的图片保存到数据库,然后从数据读取显示
- FileUpload实现将图片保存到数据库在image中显示
- php将图片以二进制保存到mysql数据库并显示
- struts2保存图片到数据库,从数据库显示图片
- 将图片保存到表中并用ajax技术获取图片
- GridView显示数据库图片
- IE開啓緩慢
- js正则表达式使用
- XML-RPC初探
- text-indent在火狐下失效的研究
- Spring事务配置的五种方式
- 将图片保存到数据库并用GridView显示
- 内存分配方式
- 数据库连接池技术
- String、StringBuilder和StringBuffer的区别
- linux 内核调试
- php session操作
- C#一个小程序的学习
- silverlight 数据绑定模式
- 检查MFC程序的内存泄露