PC Review


Reply
Thread Tools Rate Thread

Dealing with BLOBs

 
 
=?Utf-8?B?QW1pcg==?=
Guest
Posts: n/a
 
      10th Aug 2005
Hi

I'm working on a C# windows application witch retrieve BLOBs Data from
Database.
I'm doing that using SqlDataReader with SequentialAccess CommandBehavior.
My code is something like the bellow:

SqlConnection cnn = new SqlConnection(Global.ConnectionString);

SqlCommand cmd = new SqlCommand("SELECT Img FROM Imgs WHERE [item_id] =
555000000300990", cnn);

cnn.Open();

IDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
dr.Read();
long size = dr.GetBytes(0, 0, null, 0, 0); //get the length of data
byte[] values = new byte[size];

int bufferSize = 100;
long bytesRead = 0;
int curPos = 0;

while (bytesRead < size)
{
bytesRead += dr.GetBytes(0, curPos, values, curPos, bufferSize);
curPos += bufferSize;
}

This one is working perfect, but if I change the code to read data from a
Text column in DB and use GetChars, I get an exception witch means you have
to read columns in order.

Even I remove the line # 10 (long size = dr.GetBytes(0, 0, null, 0, 0);
//get the length of data)

Why this method is working for Bytes but not for Characters?

Thanks in advance
 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      10th Aug 2005
You add a text field or change Img field to your text field in SELECT
statement?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

"Amir" <(E-Mail Removed)> wrote in message
news:F266B701-4BE7-4640-863E-(E-Mail Removed)...
> Hi
>
> I'm working on a C# windows application witch retrieve BLOBs Data from
> Database.
> I'm doing that using SqlDataReader with SequentialAccess CommandBehavior.
> My code is something like the bellow:
>
> SqlConnection cnn = new SqlConnection(Global.ConnectionString);
>
> SqlCommand cmd = new SqlCommand("SELECT Img FROM Imgs WHERE [item_id] =
> 555000000300990", cnn);
>
> cnn.Open();
>
> IDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
> dr.Read();
> long size = dr.GetBytes(0, 0, null, 0, 0); //get the length of data
> byte[] values = new byte[size];
>
> int bufferSize = 100;
> long bytesRead = 0;
> int curPos = 0;
>
> while (bytesRead < size)
> {
> bytesRead += dr.GetBytes(0, curPos, values, curPos, bufferSize);
> curPos += bufferSize;
> }
>
> This one is working perfect, but if I change the code to read data from a
> Text column in DB and use GetChars, I get an exception witch means you
> have
> to read columns in order.
>
> Even I remove the line # 10 (long size = dr.GetBytes(0, 0, null, 0, 0);
> //get the length of data)
>
> Why this method is working for Bytes but not for Characters?
>
> Thanks in advance



 
Reply With Quote
 
=?Utf-8?B?QW1pcg==?=
Guest
Posts: n/a
 
      10th Aug 2005
Yea, I changed everything witch needed to be changed.
Like this:

SqlConnection cnn = new SqlConnection(Global.ConnectionString);

SqlCommand cmd = new SqlCommand("SELECT Txt FROM Notes WHERE [item_id] =
555000000300990", cnn);

cnn.Open();

IDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
dr.Read();
long size = dr.GetChars(0, 0, null, 0, 0); //get the length of data
char[] values = new char[size];

int bufferSize = 100;
long bytesRead = 0;
int curPos = 0;

while (bytesRead < size)
{
bytesRead += dr.GetChars(0, curPos, values, curPos, bufferSize);
curPos += bufferSize;
}




"Miha Markic [MVP C#]" wrote:

> You add a text field or change Img field to your text field in SELECT
> statement?
>
> --
> Miha Markic [MVP C#] - RightHand .NET consulting & development
> www.rthand.com
> Blog: http://cs.rthand.com/blogs/blog_with_righthand/
> SLODUG - Slovene Developer Users Group www.codezone-si.info
>
> "Amir" <(E-Mail Removed)> wrote in message
> news:F266B701-4BE7-4640-863E-(E-Mail Removed)...
> > Hi
> >
> > I'm working on a C# windows application witch retrieve BLOBs Data from
> > Database.
> > I'm doing that using SqlDataReader with SequentialAccess CommandBehavior.
> > My code is something like the bellow:
> >
> > SqlConnection cnn = new SqlConnection(Global.ConnectionString);
> >
> > SqlCommand cmd = new SqlCommand("SELECT Img FROM Imgs WHERE [item_id] =
> > 555000000300990", cnn);
> >
> > cnn.Open();
> >
> > IDataReader dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
> > dr.Read();
> > long size = dr.GetBytes(0, 0, null, 0, 0); //get the length of data
> > byte[] values = new byte[size];
> >
> > int bufferSize = 100;
> > long bytesRead = 0;
> > int curPos = 0;
> >
> > while (bytesRead < size)
> > {
> > bytesRead += dr.GetBytes(0, curPos, values, curPos, bufferSize);
> > curPos += bufferSize;
> > }
> >
> > This one is working perfect, but if I change the code to read data from a
> > Text column in DB and use GetChars, I get an exception witch means you
> > have
> > to read columns in order.
> >
> > Even I remove the line # 10 (long size = dr.GetBytes(0, 0, null, 0, 0);
> > //get the length of data)
> >
> > Why this method is working for Bytes but not for Characters?
> >
> > Thanks in advance

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BLOBS and VB.NET lord.zoltar@gmail.com Microsoft Dot NET 1 14th Nov 2006 10:11 PM
Writing BLOBs (through C#) Marc Gravell Microsoft C# .NET 1 1st Jun 2006 02:16 PM
updating blobs =?Utf-8?B?Sm9obks=?= Microsoft ADO .NET 3 18th Jan 2005 05:46 AM
BLOBs yang Microsoft C# .NET 2 17th Jul 2004 05:33 PM
BLOBS Kathy Zallar Microsoft Access Forms 1 17th Sep 2003 05:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:34 PM.