dbTalk Databases Forums  

Extracting Image datatype content with SQL2005?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Extracting Image datatype content with SQL2005? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #21  
Old   
Goldrush\(???\)
 
Posts: n/a

Default Re: Extracting Image datatype content with SQL2005? - 03-03-2011 , 06:44 AM






"Joe Cool" <joecool1969 (AT) live (DOT) com> wrote

Quote:
I am cross posting this request for help in both the C#,NET and the
SQLServer newsgroups in he hope that some reader of one these
newsgroups can offer some help.

I am well aware that the image datatype (as well as others) are being
phased out in some future version of SQL Server. For that reason, in
all of my personal C#.NET projects that store images use the
varbinary(max) datatype.

I am in the process of converting a VB.NET project that I use for
consulting work with a former (and hopefully soon to be repeat)
employer tp C#.NET. When originally designed, their software was based
on SQL7. Currently their software supports SQL2005. One key table in
their database is a table of images and (not sure if it still does)
but legacy databases utilize the image datatype to store images. With
SQL7 I used a SQL command line utility called TEXTCOPY to extract the
binary content of image columns to a JPG file.

This utility needs to be able to extract these images to external
files even for legacy databases that may still use the image datatype.
But I find that the technique I use to extract images from a
varbinary(max) column doesn't work for image datatypes. And I see that
SQL2005, while it still supports image datatype, the TEXTCOPY utility
is nowhere to be found.

Any ideas on how to extract image data types from a SQL2005 database
with C#.NET?
Try like this

using System.IO;
using System.Drawing;


...............................
private PictureBox myPictureBox1;
.................................

DBCon dbcon = new DBCon(); //defined by me
dbcon.Open(); //database open

string sSql = "SELECT [ImageCol] FROM [ImageDataBase] ";

DataSet ds = dbcon.GetDataSet(sSql); //Get DataSet
dbcon.Close(); //database close

if (ds != null && ds.Tables.Count>0 )
{
byte[] image = (byte[])ds.Tables[0].Rows[0]["ImageCol"];
MemoryStream ms = new MemoryStream(image, 0, image.Length);
Bitmap bitmap = new Bitmap(ms);
ms.Close();
ms.Dispose();

myPictureBox1.Picture = bitmap; //show bitmap
myPictureBox1.FitToPictureBox(); //fit image to control
}

Reply With Quote
  #22  
Old   
Arne Vajhøj
 
Posts: n/a

Default Re: Extracting Image datatype content with SQL2005? - 03-03-2011 , 05:29 PM






On 03-03-2011 07:44, Goldrush(???) wrote:
Quote:
"Joe Cool"<joecool1969 (AT) live (DOT) com> wrote in message
news:18a81576-f3f6-4a12-a5e1-0ddc351e0c5a (AT) w12g2000yqj (DOT) googlegroups.com...
I am cross posting this request for help in both the C#,NET and the
SQLServer newsgroups in he hope that some reader of one these
newsgroups can offer some help.

I am well aware that the image datatype (as well as others) are being
phased out in some future version of SQL Server. For that reason, in
all of my personal C#.NET projects that store images use the
varbinary(max) datatype.
That is what the docs says.

I am somewhat skeptical about how soon it will happen.

Using *var*(max) for new stuff absolutely makes sense.

But I would hurry slowly to convert existing code.

Quote:
I am in the process of converting a VB.NET project that I use for
consulting work with a former (and hopefully soon to be repeat)
employer tp C#.NET. When originally designed, their software was based
on SQL7. Currently their software supports SQL2005. One key table in
their database is a table of images and (not sure if it still does)
but legacy databases utilize the image datatype to store images. With
SQL7 I used a SQL command line utility called TEXTCOPY to extract the
binary content of image columns to a JPG file.

This utility needs to be able to extract these images to external
files even for legacy databases that may still use the image datatype.
But I find that the technique I use to extract images from a
varbinary(max) column doesn't work for image datatypes. And I see that
SQL2005, while it still supports image datatype, the TEXTCOPY utility
is nowhere to be found.

Any ideas on how to extract image data types from a SQL2005 database
with C#.NET?

Try like this

using System.IO;
using System.Drawing;


...............................
private PictureBox myPictureBox1;
.................................

DBCon dbcon = new DBCon(); //defined by me
dbcon.Open(); //database open

string sSql = "SELECT [ImageCol] FROM [ImageDataBase] ";

DataSet ds = dbcon.GetDataSet(sSql); //Get DataSet
dbcon.Close(); //database close

if (ds != null&& ds.Tables.Count>0 )
{
byte[] image = (byte[])ds.Tables[0].Rows[0]["ImageCol"];
MemoryStream ms = new MemoryStream(image, 0, image.Length);
Bitmap bitmap = new Bitmap(ms);
ms.Close();
ms.Dispose();

myPictureBox1.Picture = bitmap; //show bitmap
myPictureBox1.FitToPictureBox(); //fit image to control
}

Using DataSet should work, but it really does not provide
any value here that a more lightweight data reader would
not provide.

Arne

Reply With Quote
  #23  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Extracting Image datatype content with SQL2005? - 03-04-2011 , 11:18 AM



Arne Vajhøj (arne (AT) vajhoej (DOT) dk) writes:
Quote:
I am well aware that the image datatype (as well as others) are being
phased out in some future version of SQL Server. For that reason, in
all of my personal C#.NET projects that store images use the
varbinary(max) datatype.

That is what the docs says.

I am somewhat skeptical about how soon it will happen.

Using *var*(max) for new stuff absolutely makes sense.

But I would hurry slowly to convert existing code.
Given how much simpler the MAX data types are over text/image/ntext I see
all reason to change existing code. At least if you run into one of the
many quirks with the old data types.
--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

Reply With Quote
  #24  
Old   
Arne Vajhøj
 
Posts: n/a

Default Re: Extracting Image datatype content with SQL2005? - 03-04-2011 , 06:36 PM



On 04-03-2011 12:18, Erland Sommarskog wrote:
Quote:
Arne Vajhøj (arne (AT) vajhoej (DOT) dk) writes:
I am well aware that the image datatype (as well as others) are being
phased out in some future version of SQL Server. For that reason, in
all of my personal C#.NET projects that store images use the
varbinary(max) datatype.

That is what the docs says.

I am somewhat skeptical about how soon it will happen.

Using *var*(max) for new stuff absolutely makes sense.

But I would hurry slowly to convert existing code.

Given how much simpler the MAX data types are over text/image/ntext I see
all reason to change existing code. At least if you run into one of the
many quirks with the old data types.
That is an OK reason to change. It can sometimes be frustrating.

I am a lot more skeptical about the datatypes disappearing
in SQLServer 2012 (or 2015 for that matter). It would just
create too much chaos.

Arne

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.