devexpress datagrid 与imageEdit以及如何存图片到数据库
首先建立了一个数据库的表,这个表中,有一个字段是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] GO USE [SchedulerDB] GO /****** Object: Table [dbo].[Resources] Script Date: 11/19/2014 10:16:03 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE 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] GO EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'岗位' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'Resources' GO
然后与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(); }