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