uploading and saving BLOB to database?

L

Lauchlan M

Hi

I want to upload a general BLOB (jpg, doc, pdf etc) to the database.

My code for this is at the moment something like

<<

if (
(fileDischargeFile.PostedFile != null) // there is an uplaoded file
& (fileDischargeFile.PostedFile.ContentLength !=0 ) ) // of non-zero
length
{

//Get the posted file
System.IO.Stream fileDataStream =
fileDischargeFile.PostedFile.InputStream;

//Get length of file
int fileLength = fileDischargeFile.PostedFile.ContentLength;

//Create a byte array with file length
byte[] fileData = new byte[fileLength];

//Read the stream into the byte array
fileDataStream.Read(fileData,0,fileLength);

lblUploadMessage.Text = fileData.Length.ToString(); // check we got
it - testing only - (*)

// load up the data reader so we can write the file into the BLOB
field:
nxCommand_UpdateDischargeFile.Parameters["SessionID"].Value =
Request.QueryString["SessionDataID"];

nxCommand_UpdateDischargeFile.Parameters["DischargeSummaryAmendment"].Value
= fileData;
nxConnection.Open();
nxCommand_UpdateDischargeFile.ExecuteNonQuery();
nxConnection.Close();

What happens is that it all appears to work, it tells me it's uploaded file
of say 25,321 bytes (in line *, above), but when I have a look at the BLOB
in the database there appears to be nothing there.

Is the above correct, andd is it the best way to generally load a BLOB into
the database?

Thanks!

Lauchlan M
 
M

Martin Dechev

Hi, Lauchlan M,

What happens is that it all appears to work, it tells me it's uploaded file
of say 25,321 bytes (in line *, above), but when I have a look at the BLOB
in the database there appears to be nothing there.

How do you know there is nothing? Do you try to read from this field?

Have a look at the following article:

http://support.microsoft.com/?kbid=326502

Although VB.NET is used you might find it useful.
Is the above correct, andd is it the best way to generally load a BLOB into
the database?

Thanks!

Lauchlan M

Greetings
Martin
 
L

Lauchlan M

What happens is that it all appears to work, it tells me it's uploaded
file

How do you know there is nothing? Do you try to read from this field?

Because I wrote some Delphi code to unload the BLOB from the database and it
tells me the length is zero, and also when I look at it in the database
Enterprise Manager it looks empty (actually it has about 4 byte characters
in it).
Have a look at the following article:

http://support.microsoft.com/?kbid=326502

Although VB.NET is used you might find it useful.

OK, looking. The C# version is at
http://support.microsoft.com/default.aspx?scid=kb;en-us;309158

Thanks!

Lauchlan M
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top