Reference to my previous thread 21942
LLBLGEN 4.0 Rel May 15th, 2013
.Net Framework 4.0
C# Windows Application
SQL Server 2008
LLBLGEN runtime framework self servicing
I am trying to store image in sql server.
Column Image in DB is type Image I am passing Image "Picture" as data type Image.
Error: Cannot convert source type System.drawing.image to target type byte[].
Also tried memberimage.Image = Convert.ToByte(Picture);
Error: Cannot convert source type byte to target type byte[].
So far, I have created type converter class [code reproduced below], added the dll in LLBLGEN type converter folder. Defined type conversion. Anything else to do ?
But the error memberimage.Image = Picture; //cannot convert source type 'System.Drawing.Image' to target type 'byte[]' still exists
using System;
using System.ComponentModel;
using System.Drawing;
namespace TypeConverterTierMyClubCircle
{
public class TypeConverterClass : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
switch (sourceType.FullName)
{
case "System.Byte[]":
return true;
default:
return false;
}
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
switch (destinationType.FullName)
{
case "System.Byte[]":
return true;
default:
return false;
}
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,
object value)
{
if (value == null)
{
return null;
}
var cnv = new ImageConverter();
return cnv.ConvertFrom(value);
}
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture,
object value, Type destinationType)
{
if (value == null)
{
return null;
}
var cnv = new ImageConverter();
return cnv.ConvertTo(value, Type.GetType("System.Byte[]"));
}
public override object CreateInstance(ITypeDescriptorContext context,
System.Collections.IDictionary propertyValues)
{
return new Bitmap(10, 10);
}
}
}