c# - 将图像文件保存到数据库中

标签 c# .net asp.net visual-studio

在用户使用 asp.net 中的 fileupload 控件选择文件位置后,如何使用 c# 将文件保存到 SQL Server 数据库中。

最佳答案

你可以尝试这样的事情:

if (this.fileUploader.PostedFile == null ||
    this.fileUploader.PostedFile.ContentLength < 1)
{
   this.LabelError.Text = this.GetGlobalResourceObject("Messages", "NoFileToUpload")
                              .ToString();
   return;
}

MyTableWithImageField i = new MyTableWithImageField();

i.ImageData = this.fileUploader.FileBytes;

command.CommandText = @"InsertMyTableWithImageField";
command.CommandType = CommandType.StoredProcedure;

command.Parameters.AddWithValue("@ImageData", i.ImageData);

您可能还想从 MSDN 中查看:Uploading Files in ASP.NET 2.0

关于c# - 将图像文件保存到数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6570554/

相关文章:

asp.net - 使用 asp.net 4.5 OAuth 用 clientid 和 secret 注册谷歌

javascript - 一旦标签都有值,就动态地对它们的值求和

c# - 追加两个多维数组对象 [,]

c# - 使用 Copy Local 引用另一个项目的引用

C# 泛型方法值

.NET 的 Java 正则表达式

c# - 使用 LINQ 对字符串数组进行排序

c# - C++ 到 C# 的包装 - 如何处理 C# 中的双指针数组

C# LINQ 问题

c# - Automapper - 使用嵌套 View 模型映射 View 模型