gpt4 book ai didi

.net - 将图像存储在数据库中

转载 作者:行者123 更新时间:2023-12-01 13:02:40 25 4
gpt4 key购买 nike

我有一个 ASP 页面。在 asp 页面中,我有一个图像控件。图像控件中有一个图像。我想将此图像保存在数据库中。在数据库中,特定的字段数据类型是图像。怎么可能?

最佳答案

查看这篇文章: Save and Retrieve Images from the Database using ASP.NET 2.0 and ASP.NET 3.5

上面文章的例子

首先,您需要像这样将图像转换为字节:

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);
}

然后在添加到数据库时使用 imgByte 作为值。

关于.net - 将图像存储在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5014217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com