如何在数据库中插入图像? [英] how to insert a image in database ?

查看:83
本文介绍了如何在数据库中插入图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



请帮帮我,



如何在数据库中插入图片通过c#(上传文件),同时在重新启动它时应该显示在图片框中。



感谢你。

hello friends,

please help me out,

how to insert an image in database through c#(upload a file) and also while retriving it should display in picturebox.

thanking you.

推荐答案

试试这个链接,工作正常。



http://forums.asp.net/t/1922364.aspx [ ^ ]



如果您想将图像文件存储在Web服务器中并将图像路径保存在Db中,您可以选择此链接

http://www.aspsnippets.com/Articles/Retrieve-images-using-a-file- path-in-database-in-ASPNet.aspx [ ^ ]





最好将图像存储在Web服务器而不是SQL服务器中,并将文件路径保存在表列中,如果您正在处理mo重新映像数量,

如果图像数量较少,可以在SQL Server中保存图像对象。
Try this link, works fine.

http://forums.asp.net/t/1922364.aspx[^]

If you wanna store the image file in web server and save the image path in Db you can prefer this link
http://www.aspsnippets.com/Articles/Retrieve-images-using-a-file-path-stored-in-database-in-ASPNet.aspx[^]


Its better to store the images in web server instead of SQL server and save the file path in table column, if you are handling more number of images,
in case of less number of images you can save the image object in the SQL Server.


请参阅此链接,

http://www.aspsnippets.com/Articles/How-to-save-insert-Image-in-Database-in-ASPNet-using-C-and-VBNet.aspx [<一个href =http://www.aspsnippets.com/Articles/How-to-save-insert-Image-in-Database-in-ASPNet-using-C-and-VBNet.aspx\"target =_ blanktitle = 新窗口> ^ ]
Refer this link,
http://www.aspsnippets.com/Articles/How-to-save-insert-Image-in-Database-in-ASPNet-using-C-and-VBNet.aspx[^]


在Web应用程序中创建一个文件夹图像,并在后端(数据库)中将varbinary数据类型作为变量

它很容易且工作顺利!

Make one folder images in your web application and take varbinary datatype as variable in your backend(database)
its easy and work smoothly!
protected void Button1_Click(object sender, EventArgs e)
       {
           if (FileUpload1.HasFile)
               try
               {
                   FileUpload1.SaveAs(Server.MapPath("~/your folder name/" + FileUpload1.FileName));
                   Label1.Text = "File name: " +
                        FileUpload1.PostedFile.FileName + "<br>" +
                        FileUpload1.PostedFile.ContentLength + " kb<br>" +
                        "Content type: " +
                        FileUpload1.PostedFile.ContentType;
                   filename.Text = FileUpload1.FileName;
               }
               catch (Exception ex)
               {
                   Label1.Text = "ERROR: " + ex.Message.ToString();
               }
           else
           {
               Label1.Text = "You have not specified a file.";
           }
       }


这篇关于如何在数据库中插入图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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