如何在数据库中保存图像 [英] how to save image in database
本文介绍了如何在数据库中保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在具有列名Image和数据类型作为图像的数据库中保存图像路径?
how can i save the image path in database which has column name Image and datatype as image?
推荐答案
不知道要将图像保存到哪个数据库我只能建议以下内容:
数据库通常没有图像数据类型(不是我相当熟悉的数据库),因此您需要将图像保存为BLOB或二进制大对象.
Not knowing what database you want to save your image to all I can suggest is the following:
Databases do not generally have an image datatype(not the databases I am reasonably familiar with) - so you will need to save the image as a BLOB or binary large object.
简单:
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myImage) VALUES (@IM)", con))
{
byte[] imageData = File.ReadAllBytes(@"F:\Temp\Picture.jpg");
com.Parameters.AddWithValue("@IM", imageData);
com.ExecuteNonQuery();
}
}
是的! SQL Server的数据类型为图像 [将图像保存到SQL Server 2000数据库 [
Yes! the SQL server has the datatype image[^], refer this for storing images:
Save An Image Into SQL Server 2000 Database[^]
hope it helps :)
这篇关于如何在数据库中保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文