在用户使用 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/