Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

DataBind DBNull Image

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeronimo Bertran - 27 Nov 2004 00:13 GMT
I am using forms databinding to show an image in the database in a
pictureBox.  To do this I am handling the Format event to convert the byte
[] to a bitmap:

Binding bind = new System.Windows.Forms.Binding("Image", this.dataSet1,
"Employee.Image");
bind.Format += new ConvertEventHandler(Image_Format);

private void Image_Format(object sender, ConvertEventArgs e)
{
    if (e.Value is System.DBNull)
    {

              ///   How do we handle the DBNull???
        return;
    }

    // e.Value is the original value
    Byte[] img = (Byte[]) e.Value;

    MemoryStream ms = new MemoryStream();
    ms.Write(img, 0, img.Length);
       Bitmap bmp = new Bitmap(ms);
    ms.Close();

       // Writes the new value back
    e.Value = bmp;
}

My problem occurs when the value in the database is NULL.    if I don't do
anything then I get an Invalid cast from System.DBNull to
System.Drawing.Image.   I also tried :

e.Value = (Bitmap) null;

but i get a memory exception

Thanks

Jeronimo
Sijin Joseph - 29 Nov 2004 04:50 GMT
Have you tried setting e.Value = null ?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I am using forms databinding to show an image in the database in a
> pictureBox.  To do this I am handling the Format event to convert the byte
[quoted text clipped - 36 lines]
>
> Jeronimo
Jeronimo Bertran - 01 Dec 2004 03:35 GMT
Yes, I tried setting e.Value to null but I later get a memory exception.

> Have you tried setting e.Value = null ?
>
> Sijin Joseph
> http://www.indiangeek.net
> http://weblogs.asp.net/sjoseph
Tampa .NET Koder - 01 Dec 2004 18:35 GMT
You could create a 1px gif image that would become the placeholder for that
image box if the field is null.  Or, create a standard image file that a user
can see if there is not image avaliable.  Use either case as the image source
for the picture box

> I am using forms databinding to show an image in the database in a
> pictureBox.  To do this I am handling the Format event to convert the byte
[quoted text clipped - 36 lines]
>
> Jeronimo

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.