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
>
>
>