在sql中绑定图像 [英] binding image in sql

查看:79
本文介绍了在sql中绑定图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在sql中绑定图像,我需要获取并设置图像的属性值



例如:



  private   string  _Username; 

public string 用户名
{
get { return _username;}
set {_ username = value ;}





我想要图像的语法。

解决方案

就像您为用户名成员提供字符串类型一样,您将为Image成员提供特定的数据类型。



这取决于您的应用程序框架,为您的数据选择哪种对象类型。 Bitmap [ ^ ], 图像 [ ^ ], byte [] [ ^ ]以及所有其他此类数据类型可满足您定义Image对象的需要。然后,您可以 - 在需要时 - 将它们转换为图形对象以表示您的数据。



在SQL中,image字段也是一个包含byte数组的字段。给出了图像的字节数组(实际上是文件)的值,然后可以检索为字节数组并转换为文件等等。



我也会给你提示,在使用getter和setter时不要创建另一个成员。使用它,例如,


  public  字符串用户名{获取;  set ; } 





这与检索用户名和设置用户名等具有相同的功能。


请参考以下链接......

这里图像被转换为​​字节数组并保存在DB中并检索那些字节数组。





http://www.c-sharpcorner.com/UploadFile/0f100d/storing-and-retrieving-image-from-sql-server-database-in-wpf/ [ ^ ]



你可以拥有这样的房产

public BitmapImage bitmapImageSource {get;组; }

I want to binding image in sql, I need get and set property value of image

for ex:

private string _Username;

public string Username
{
get {return _username;}
set{_username=value;}



I want syntax for image.

解决方案

Just the way you're giving string type for your username member, you will be giving a specific data type to your Image member.

It depends on your framework of application, to choose which object type for your data. Bitmap[^], Image[^], byte[][^] and all other such data types can fulfill your need of defining an Image object. You can then -- when required -- convert them into graphics object to represent your data.

In SQL, image field is also a field that contains arrays of byte. Which is given the value of byte arrays of the image (actually a file) and then can be retrieved as byte arrays and converted to files and so on.

I would also tip you, to not create another member while using getters and setters. Use it like,

public string Username { get; set; }



This would have the same functionality of retrieving the Username and setting the Username and so on.


Refer the below link...
Here the image is converted to byte array and saved in DB and retrieving those byte array.


http://www.c-sharpcorner.com/UploadFile/0f100d/storing-and-retrieving-image-from-sql-server-database-in-wpf/[^]

you can have a property like this
public BitmapImage bitmapImageSource { get; set; }


这篇关于在sql中绑定图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆