如何从asp.net中的sql数据库中检索图像 [英] how to retrieve images from sql database in asp.net
问题描述
嗨每一个;
i我是asp.net的初学者。
这里我有一个问题是:
我有两个webfrom在一种形式我上传数据库中的图像。这是成功上传的。
第二种形式的
我有一个图像按钮和一个图像框。我希望当用户点击图像按钮时,新的上传图像会显示在图像框中。
换句话说我想知道如何从数据库中检索图像并在图像框中显示。
请尽快给我一些提示;
提前感谢。
这里是我的图片上传代码:
hi every one;
i am beginners in asp.net.
here i have a problem is that:
I have two webfrom in one form i upload images in database. That is uploaded successfully.
in 2nd form i have one image button and one image box. I want that when user click image button then new uploaded image is displayed in image box.
in other words i want to know how to retrieve images from database and display in image box.
please give me some hints as soon as possible;
thanks in advance.
here is my image upload code:
SqlConnection con = new SqlConnection(@"connection string");
SqlCommand com;
photo phobj=new photo();
protected void btnsubmit_Click1(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
String filename = FileUpload1.PostedFile.FileName;
String FileExtension = Path.GetExtension(filename).ToLower();
String[] ExtesionAllowed = { ".png", ".gif" };
if (FileExtension.Contains(Path.GetExtension(filename).ToLower()))
{
try
{
String FileSavePath = Server.MapPath("~/Photos/");
FileUpload1.PostedFile.SaveAs(FileSavePath + FileUpload1.PostedFile.FileName);
}
catch (Exception)
{
lblmsg.Text = "unable to upload.";
}
}
else
{
lblmsg.Text = "File Extension " + Path.GetExtension(filename).ToLower() + " is not allowed";
}
phobj.url = Path.GetFileName(filename);
phobj.alpha = drp_name.SelectedItem.Text.ToString();
phobj.message = txtname.Text;
con.Open();
string query = "Insert Into Images(url,name,message)Values('" + phobj.url + "','" + phobj.alpha + "','" + phobj.message + "')";
com = new SqlCommand(query, con);
if (com.ExecuteNonQuery() > 0)
{
lblmsg.Text = "Images Submited";
}
}
else
{
lblmsg.Text = "Operation Failed...please try again...";
}
con.Close();
}
推荐答案
你可以用Google搜索 [ ^ ]。请参阅以下顶部链接:
http: //nareshkamuni.blogspot.in/2012/02/insert-image-into-sqlserver-database-by.html [ ^ ]
将图像从sql server加载到图像控制asp.net [ ^ ]
如何从sql server数据库中检索图像并在asp .net图像控件上显示? [ ^ ]
如何在sql server中插入图像 [ ^ ]
也请参阅CP搜索结果。
< a href =http://www.codeproject.com/search.aspx?doctypeid=5&q=SQL+%28images+OR+image%29> SQL(图像或图像) [ ^ ] < br $>
- Amit
You could have Googled[^] for it. See the top links below:
http://nareshkamuni.blogspot.in/2012/02/insert-image-into-sqlserver-database-by.html[^]
load image from sql server to image control asp.net[^]
how to retrieve image from sql server database and show on asp .net image control?[^]
how to insert image in sql server[^]
See the CP search result also.
SQL (images OR image)[^]
--Amit
Hi Wajid,>
我之前在同一项任务上工作过,我很高兴你在这里提出这个问题....
你可以参考这个Link [ ^ ]示例代码。
我希望这会对你有所帮助。
Hi Wajid,
I worked on the same task earlier and I am pleased you asked this question here....
You can refer this Link[^] for sample code.
I hope this would help you a bit.
hi兄弟..你能告诉我的是,这个代码也适用于移动图像上传我的意思是我想在手机上保存图像而不是检索它..请帮助我,如果你可以..谢谢。
hi bro .. can you tell me please that is this code also work for mobile image upload I mean i want to saved image on mobile and than retrieved it .. please help me if you can .. thanks.
>
这篇关于如何从asp.net中的sql数据库中检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!