首页 > 代码库 > devexpress datagrid 与imageEdit以及如何存图片到数据库 z

devexpress datagrid 与imageEdit以及如何存图片到数据库 z

http://blog.csdn.net/haoyujie/article/details/41277703

首先建立了一个数据库的表,这个表中,有一个字段是image类型(SQL Server数据库)

USE [SchedulerDB]GO/****** Object:  Table [dbo].[Resources]    Script Date: 11/19/2014 10:16:03 ******/IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N‘[dbo].[Resources]‘) AND type in (N‘U‘))DROP TABLE [dbo].[Resources]GOUSE [SchedulerDB]GO/****** Object:  Table [dbo].[Resources]    Script Date: 11/19/2014 10:16:03 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[Resources](	[UniqueID] [int] IDENTITY(1,1) NOT NULL,	[ResourceID] [int] NOT NULL,	[ResourceName] [nvarchar](50) NULL,	[Color] [int] NULL,	[Image] [image] NULL,	[CustomField1] [nvarchar](max) NULL, CONSTRAINT [PK_Resources] PRIMARY KEY CLUSTERED (	[UniqueID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]GOEXEC sys.sp_addextendedproperty @name=N‘MS_Description‘, @value=http://www.mamicode.com/N‘岗位‘ , @level0type=N‘SCHEMA‘,@level0name=N‘dbo‘, @level1type=N‘TABLE‘,@level1name=N‘Resources‘>

 

然后与datagrid进行了映射。

技术分享


然后,在image字段上,绑定一个ImageEdit编辑控件。


然后运行,


技术分享

然后,就得到这个错误:Object must implement IConvertible

技术分享

技术分享


把PictureStoreMode改成ByteArray

然后就OK了。

对了,保存所对应的代码为:

       void saveToolStripButton_Click(object sender, EventArgs e)        {             this.Validate();            this.resourcesBindingSource.EndEdit();            this.resourcesTableAdapter.Update(this.schedulerDBDataSet);            schedulerDBDataSet.AcceptChanges();        }

 

devexpress datagrid 与imageEdit以及如何存图片到数据库 z