【发布时间】:2017-06-27 00:11:12
【问题描述】:
这是我在 Grid(WPF) 中打印图像的 C# 代码,现在我想 将此图像存储在数据库中,我在数据库中有名为的列 图片。我有所有其他代码数据库连接等。请告诉我哪个 方法最适合在数据库中存储图像?
private void button_Browse_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog op = new OpenFileDialog();
op.Title = "Select a picture";
op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
"JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
"Portable Network Graphic (*.png)|*.png";
if (op.ShowDialog() == true)
{
imgPhoto.Source = new BitmapImage(new Uri(op.FileName));//this line print image in Grid
}
}
【问题讨论】:
-
什么数据库?这在很大程度上取决于您正在谈论的具体数据库系统......
-
@marc_s SQl Server Database at column datatype is image.
-
ntext、text和image数据类型将在 SQL Server 的未来版本中删除。避免在新的开发工作中使用这些数据类型,并计划修改当前使用它们的应用程序。请改用nvarchar(max)、varchar(max)和varbinary(max)。 See details here -
@marc_s 如果我使用 varchar(max) 或 carbinary(max) 那么我将如何将图像类型转换为 varchar(max) 或其他
-
对于 二进制 数据(如图像),使用
varbinary(max)- 您应该能够简单地将列的数据类型转换为ALTER TABLE dbo.YourTable ALTER COLUMN YourColumn VARBINARY(MAX);
标签: sql-server wpf database image-processing c#-4.0