如何使用C#在Microsoft SQL Server和ASP.NET中存储和检索图像? [英] How to store and retrieve images in Microsoft SQL Server and ASP.NET using C# ?

查看:79
本文介绍了如何使用C#在Microsoft SQL Server和ASP.NET中存储和检索图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计..

我正在处理一个项目..我无法在数据库中存储和检索图像..

我可以在Web服务器上存储图像吗?从他们检索并执行所需的操作?????



thanx

Hey guys..
I m working on a project..i m unable to store and retrieve image in database..
Can I store Images on Web server and retrieve from their and perfom the required operations?????

thanx

推荐答案

试试这些链接它可能对你有所帮助..



您也可以尝试将图像文件存储在服务器上并将路径存储在Sql表上..

by这些链接





http://stackoverflow.com/questions/1831801/retrieving-images-using-a-file-path-stored-in-a-sql -database



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





通过将图像对象存储到数据库表中尝试以下链接。



使用标记过程和C#.net 从SQL Server存储和检索图像[ ^ ]





http://www.aspdotnet-suresh.com/2011/01/how-to-insert-images-into-database-and.html [ ^ ]







http://www.redmondpie.com/inserting-in-and-retrieving-image-f rom-sql-server-database-using-c / [ ^ ]
Try these links it might help you..

you can also try by storing the image files on the server and store the paths on the Sql table..
by these links


http://stackoverflow.com/questions/1831801/retrieving-images-using-a-file-path-stored-in-a-sql-database

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


by storing image object to the database tables try below links.

Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]


http://www.aspdotnet-suresh.com/2011/01/how-to-insert-images-into-database-and.html[^]



http://www.redmondpie.com/inserting-in-and-retrieving-image-from-sql-server-database-using-c/[^]


查看此链接

http://www.dotnetgallery.com /kb/resource21-How-to-store-and-retrieve-images-from-SQL-server-database-using-aspnet.aspx [ ^ ]


看看这个:为什么我得到参数无效。我从数据库中读取图像时出现异常? [ ^ ] - 不要担心名称,它解释了如何不这样做,然后覆盖代码来正确完成。



检索它们(通常)也非常简单:

Have a look at this: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^] - dont' worry about the name, it explains how not to do it, then covers the code to do it properly.

Retrieving them is (generally) pretty trivial as well:
using (SqlConnection con = new SqlConnection(GenericData.DBConnection))
    {
    con.Open();
    using (SqlCommand cmd = new SqlCommand("SELECT ImageData FROM Images WHERE Id=@ID", con))
        {
        cmd.Parameters.AddWithValue("@ID", Id);
        SqlDataReader r = cmd.ExecuteReader();
        if (r.Read())
            {
            MemoryStream ms = new MemoryStream((byte[])r["ImageData"]);
            MyImage = Image.FromStream(ms);
            }
        }
    }

然后,您可以通过您需要的任何控制在您的应用程序中使用MyImage。

You can then use MyImage in your application via whatever control you require.


这篇关于如何使用C#在Microsoft SQL Server和ASP.NET中存储和检索图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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