These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to Insert IMAGE into Database??
PostPosted: Thu Aug 24, 2006 7:26 am 
Newbie

Joined: Tue Jul 18, 2006 2:29 pm
Posts: 10
I need insert Image to into SQL Server Database.

If I use ADO.NET, everything is ok. When I change it to NHibernate, it's excuted, and insert string field into database, but image could not insert.

I use NHibernate type: BinaryBlob ; .NET Type: Byte[]; SQLServer Type: image.

Plesease show a solution....Thanks....


Top
 Profile  
 
 Post subject: Re: How to Insert IMAGE into Database??
PostPosted: Thu Aug 24, 2006 9:52 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
texudo wrote:
I use NHibernate type: BinaryBlob ; .NET Type: Byte[]


We do it exactly the same way, so I think this is not really an NHibernate issue. It propbably depends on how you fill your byte array. This is how we do it:
Code:
byte[] photo = null;
if (this.openFileDialogImage.ShowDialog() == DialogResult.OK)
{
   try
   {
      Image img = Image.FromFile(this.openFileDialogImage.FileName);
      MemoryStream ms = new MemoryStream();
      img.Save(ms,ImageFormat.Jpeg);
      ms.Seek(0,SeekOrigin.Begin);
      photo = ms.ToArray();
   }
   catch
   {
      MsgBoxHelper.Error("Invalid image");
   }
}

After which the variable photo is assigned to the property of type byte[] that is mapped as BinaryBlob. Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 24, 2006 10:21 am 
Newbie

Joined: Thu Aug 24, 2006 9:48 am
Posts: 1
Hi how can I do to delete this post ?
I did a stupid mistake in my code that took me time to find, and now it doesn't fit the topic...

Sorry,
Air'V


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.