如何使用asp.net中的文件上载控件在sql服务器中检索图像 [英] how to retrieve images in sql server using file Upload Control in asp.net

查看:57
本文介绍了如何使用asp.net中的文件上载控件在sql服务器中检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从sql server数据库中检索图像到asp.net中的aspx页面.
请帮我,并向我发送代码.

I want to retrieve images from sql server database to my aspx page in asp.net.
Pls help me out and also send me code for it.

推荐答案

1.在SQL中编写一个存储过程,以检索表列,包括如下所示的图像列.
1. Write a store procedure in SQL for retrieving table columns including your image column like below.
SELECT Id,Name,Email,ImageName FROM Customer



2.根据您的要求在DataTable/DataSet/List< t>(客户类型)中捕获此数据.

3.从您的问题来看,我认为您需要显示图像.因此,在aspx页面中,使用转发器/数据列表/gridview控件进行数据绑定.点击此处 [此处 [



2. Capture this data in DataTable/DataSet/List<t>(customer type) as per your requirement.

3. From your question, I think you need to display images. So in the aspx page use a repeater/datalist/gridview control for data binding. Click here[^] to view an example of DataList control

4. One more good example here[^]

Hope it helps.


在asp.net页面中检索图像的另一种方法是获取
的路径. 文件.

步骤1:将此代码放入按钮事件中,并在解决方案中创建一个名为uploads的文件夹.
FileUpload1.SaveAs(Server.MapPath("Uploads").toString()+ @"\" + FileUpload1.Filename);
Image1.ImageUrl = @〜\ uploads \" + FileUpload1.FileName;
Label1.Text = FileUpload1.FileName; //在标签控件中获取文件名.

if(FileUpload1.PostedFile!= null && FileUpload1.PostedFile.FileName!=")
{
HttpPostedFile hpfile = FileUpload1.PostedFile;
Byte [] img =新的Byte [hpfile.contentLength];
hpfile.InputStream.Read(0,img,hpfile.ContentLength);

}
步骤2:将其放在另一个按钮控件中

Response.Redirect("Showfile.aspx?imgid =" + Label1.Text);

步骤3:现在页面已被重定向.

步骤4:要在另一个页面中检索图像,请键入可能在页面加载事件中",然后拖动图像控件:

字符串s = Request.QueryString ["imgid"];
Image1.ImageUrl = @〜\ uploads \" + s;

非常简单...
Another way to retrieve image in your asp.net pages is to get the path of the
file.

Step 1: Put this code in a button event and also create a folder named uploads in the solution.
FileUpload1.SaveAs(Server.MapPath("Uploads").toString()+@"\"+FileUpload1.Filename);
Image1.ImageUrl=@"~\uploads\"+FileUpload1.FileName;
Label1.Text = FileUpload1.FileName; // Gets the filename in a label control.

if(FileUpload1.PostedFile!=null && FileUpload1.PostedFile.FileName!="")
{
HttpPostedFile hpfile = FileUpload1.PostedFile;
Byte[] img = new Byte[hpfile.contentLength];
hpfile.InputStream.Read(0,img,hpfile.ContentLength);

}
Step 2: put this in another button control

Response.Redirect("Showfile.aspx?imgid="+Label1.Text);

Step 3: Now the page have been redirected.

Step 4: To retrieve the image in another page type this "might be in a page load event" and also drag a image control:

string s = Request.QueryString["imgid"];
Image1.ImageUrl=@"~\uploads\" + s;

Very simple...


这篇关于如何使用asp.net中的文件上载控件在sql服务器中检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆