getting data with store procedure

Where to put a result to get byte array ?
A variable that I get from store procedure is a blog.

I use this code but I have to put a result into byte array, because it is a blog.

SqlConnection conn =null;

byte[] Profile =null;

conn =new

SqlConnection(sConnString);

conn.Open() ;

SqlCommand cmd =new SqlCommand("GetProfile", conn);

cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add (new SqlParameter ( "@UserID", UserID ));

SqlDataReader ProfileReader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);

[999 byte] By [HrvojeVoda] at [2008-2-6]
# 1

here's some code that will help you



int bufferSize = 100;
byte[] byteBuffer = new byte[bufferSize];
long startIndex = 0;
long retval = 0;
// Open the connection and read data into the DataReader.
_conn.Open();

SqlDataReader myReader = getEmp.ExecuteReader(CommandBehavior.SequentialAccess);
MemoryStream memStream = new MemoryStream();

while (myReader.Read())
{

// Reset the starting byte for the new BLOB.
startIndex = 0;

// Read the bytes.
retval = myReader.GetBytes(1, startIndex, byteBuffer, 0, bufferSize);

// Read all the bytes
while (retval == bufferSize)
{
memStream.Write(byteBuffer,0,(int)retval);
memStream.Flush();

// Reposition the start index to the end of the last buffer and fill the buffer.
startIndex += bufferSize;
retval = myReader.GetBytes(1, startIndex, byteBuffer, 0, bufferSize);
}

// Write the remaining buffer.
memStream.Write(byteBuffer, 0, (int)retval);

}

// Get all the Bytes
byte[] totalBytes = memStream.ToArray();
// Close the reader and the connection.
myReader.Close();
_conn.Close();
}



Regards,
Saurabh Nandu
www.MasterCSharp.com
www.AksTech.com

SaurabhNandu at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# IDE...