Better way to read Blob from SQL into String / Control

E

Earl Teigrob

I am saving HTML in a SQL Server 2000 Image (blob) field. I need retrieve
it and render it to the user. Since i have never done this, I was wondering
what the best way would be to accomplish this. The following code I wrote
works, but seems quite combersome to me. Is there a better way??? Thanks

SqlDtr.Read();

string s="";

byte[] ByteData = new byte[10000];

long ArraySize = SqlDtr.GetBytes(0,0, ByteData, 0, 10000);

for (int i = 0;i<ArraySize;i++)

{

s+=Convert.ToChar(ByteData);

}
 
E

Earl Teigrob

Here is my revised code for reading from a BLOB to a string

SqlDtr.Read();

int bufferSize = 100;

byte[] ByteArray = new byte[bufferSize];

System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

int startIndex=0;

string s="";


long ReadChars = SqlDtr.GetBytes(0,0, ByteArray, 0, bufferSize);

while (ReadChars == bufferSize)

{

s+= enc.GetString( ByteArray );

startIndex += bufferSize;

ReadChars = SqlDtr.GetBytes(0,startIndex, ByteArray, 0, bufferSize);

}

s+= enc.GetString(ByteArray);

Response.Write("Output is : " + s);
 
G

George Ter-Saakov

Why you do not want to keep data as Text in MS SQL?

George.

Earl Teigrob said:
Here is my revised code for reading from a BLOB to a string

SqlDtr.Read();

int bufferSize = 100;

byte[] ByteArray = new byte[bufferSize];

System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

int startIndex=0;

string s="";


long ReadChars = SqlDtr.GetBytes(0,0, ByteArray, 0, bufferSize);

while (ReadChars == bufferSize)

{

s+= enc.GetString( ByteArray );

startIndex += bufferSize;

ReadChars = SqlDtr.GetBytes(0,startIndex, ByteArray, 0, bufferSize);

}

s+= enc.GetString(ByteArray);

Response.Write("Output is : " + s);





Earl Teigrob said:
I am saving HTML in a SQL Server 2000 Image (blob) field. I need retrieve
it and render it to the user. Since i have never done this, I was wondering
what the best way would be to accomplish this. The following code I wrote
works, but seems quite combersome to me. Is there a better way??? Thanks

SqlDtr.Read();

string s="";

byte[] ByteData = new byte[10000];

long ArraySize = SqlDtr.GetBytes(0,0, ByteData, 0, 10000);

for (int i = 0;i<ArraySize;i++)

{

s+=Convert.ToChar(ByteData);

}

 
E

Earl Teigrob

I knew I would get that question...this is not my design...

George Ter-Saakov said:
Why you do not want to keep data as Text in MS SQL?

George.

Earl Teigrob said:
Here is my revised code for reading from a BLOB to a string

SqlDtr.Read();

int bufferSize = 100;

byte[] ByteArray = new byte[bufferSize];

System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

int startIndex=0;

string s="";


long ReadChars = SqlDtr.GetBytes(0,0, ByteArray, 0, bufferSize);

while (ReadChars == bufferSize)

{

s+= enc.GetString( ByteArray );

startIndex += bufferSize;

ReadChars = SqlDtr.GetBytes(0,startIndex, ByteArray, 0, bufferSize);

}

s+= enc.GetString(ByteArray);

Response.Write("Output is : " + s);





Earl Teigrob said:
I am saving HTML in a SQL Server 2000 Image (blob) field. I need retrieve
it and render it to the user. Since i have never done this, I was wondering
what the best way would be to accomplish this. The following code I wrote
works, but seems quite combersome to me. Is there a better way??? Thanks

SqlDtr.Read();

string s="";

byte[] ByteData = new byte[10000];

long ArraySize = SqlDtr.GetBytes(0,0, ByteData, 0, 10000);

for (int i = 0;i<ArraySize;i++)

{

s+=Convert.ToChar(ByteData);

}


 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top