如何在SQL Server数据库中存储图像 [英] How to store images in sql server data base

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

问题描述

你好朋友

是否有可能将图像存储在sql server数据库中.

感谢U.

Hi friends

Is there any possible to store the images in sql server data base.

Thank U.

推荐答案

阅读以下内容: ^ ]
Read the following : Storing and Retrieving Images from SQL Server Using Strored Procedures and C#.net[^]


google停止工作了吗?

尝试在 google [ CodeProject文章 [ ^ ]或 CodeProject质量检查 [ ^ ]

这是简单的代码段,使用FileUpload控件将图像存储在SQL中.
Does google stops working?

Try search on google[^] first.

You can also try search on CodeProject Articles[^] or CodeProject QA[^]

This is simple code snippets which stores image in SQL using FileUpload control
FileStream file = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
            BinaryReader str1 = new BinaryReader(file);
            byte[] bit = str1.ReadBytes(Convert.ToInt32( file.Length));
            SqlConnection connection = new SqlConnection("server=(local);database=test;integrated security=true");
            connection.Open();
            SqlCommand command = new SqlCommand();
            command.Connection = connection;
            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@Photo",bit);
            command.CommandText = "INSERT INTO image1(pic) VALUES (@Photo)";
            command.ExecuteNonQuery();
            connection.Close();


您要将图像文件存储在数据库中,请转到以下位置:-
首先获取FileUpload控件,并提供该控件的ID,例如fileUpload.
现在在button_Click上单击一个按钮,编写以下代码:-

You want to store your image file in database o.k here you go:-
first take a FileUpload Control provide the Id of this control say fileUpload.
now take a button on button_Click write the following code:-

int length = fileUpload.PostedFile.ContentLength;
byte[] imgByte = new byte[length];
HttpPostedFile hpf = fileUpload.PostedFile;
hpf.InputStream.Read(imgByte, 0, length);



现在将imgByte对象插入数据库.
记住您的数据库列的数据类型必须为Image类型的图像.



Now insert imgByte object into your database.
Remember datatype of your database column for Image must of type Image.


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

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