简体   繁体   English

如何使用 C# 从 sql server 检索二进制数据图像?

[英]How to retrieve binary data image from sql server using C#?

I am developing a windows form application and I need to save and retrieve an image from an sql database.我正在开发一个 windows 窗体应用程序,我需要从 sql 数据库中保存和检索图像。 Actually I am storing the image values in a byte array but while I am retrieving data, I am not able to display the image.实际上,我将图像值存储在字节数组中,但是在检索数据时,我无法显示图像。 I have given my code below:我在下面给出了我的代码:

DataTable dtgetfeedback = Feedback.BOFeedBackRating.GetFeedBackratingcount(setFBRTID);

if (dtgetfeedback.Rows.Count > 0)
{
    gv_feedbackrating.DataSource = dtgetfeedback;
}
else
{
    gvdtgetdetail.Rows.Clear();
    DataRow drToAdd = gvdtgetdetail.NewRow();
    gvdtgetdetail.Rows.Add(drToAdd);
    gvdtgetdetail.AcceptChanges();
    gv_feedbackrating.DataSource = gvdtgetdetail;
}

Image values are stored bytearray图像值存储字节数组

图像值存储字节数组

To show images based on byte arrays, assign RepositoryItemPictureEdit to the necessary column by setting the GridColumn.ColumnEdit property.要显示基于字节数组的图像,请通过设置GridColumn.ColumnEdit属性将RepositoryItemPictureEdit分配给必要的列。 In addition, set the RepositoryItemPictureEdit.PictureStoreMode property to ByteArray.此外,将RepositoryItemPictureEdit.PictureStoreMode属性设置为 ByteArray。

Refer this - Saving and loading binary images into a picture edit control请参阅此- 将二进制图像保存和加载到图片编辑控件中

When you have stored images in byte array format then it should be byte array format during retrieval from the database.当您以字节数组格式存储图像时,在从数据库中检索时它应该是字节数组格式。 Then add Change the PictureEdit's PictureStoreMode property to ByteArray然后添加将 PictureEdit 的PictureStoreMode 属性更改为 ByteArray

PictureEdit1.Properties.PictureStoreMode = DevExpress.XtraEditors.Controls.PictureStoreMode.ByteArray;

Related to view of image in the cells, By default, the RepositoryItemPictureEdit.SizeMode is the PictureSizeMode.Clip enumeration value of Clip.与单元格中的图像视图相关,默认情况下, RepositoryItemPictureEdit.SizeMode是Clip 的PictureSizeMode.Clip枚举值。 You may set the PictureSizeMode.Squeeze value.您可以设置 PictureSizeMode.Squeeze 值。 You may also specify the picture alignment at RepositoryItemPictureEdit.PictureAlignment .您还可以在RepositoryItemPictureEdit.PictureAlignment 中指定图片对齐方式。

References:参考:
Bind a byte array to a PictureEdit 将字节数组绑定到图片编辑
byte array column to image display 字节数组列到图像显示
How to load a picture into the repositoryitemPictureEdit 如何将图片加载到存储库itemPictureEdit
ImageEdit binding 图像编辑绑定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM