【发布时间】:2020-03-24 15:46:47
【问题描述】:
我对此真的很陌生,但我正在学习如何将图像存储在 SQL Server 数据库中。一切似乎都很好,但是无法在数据库中查看已存储的图像。我想知道有没有一种方法可以在数据库本身中存储和查看?
我的代码正确存储了图像,但我希望能够在 SQL Server 中单击它并显示图像:
FileUpload img = (FileUpload)imgUpload;
Byte[] imgByte = null;
if (img.HasFile && img.PostedFile != null)
{
// To create a PostedFile
HttpPostedFile File = imgUpload.PostedFile;
// Create byte Array with file len
imgByte = new Byte[File.ContentLength];
// Force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength);
}
string query = "insert into dbo.sell_trans (photo ) values (@eimg)";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@eimg", imgByte);
cmd.ExecuteNonQuery();
conn.Close();
输出:
【问题讨论】:
-
您想在 SSMS 中查看它吗?不确定是否有任何内置功能。但是,创建一个读取记录并显示图像的应用程序应该相对容易。可能少于 50 行代码。
标签: c# asp.net sql-server