jtdagger
asked on
Adding OLE objects to a dataset
I am trying to pass two BLOB objects to a Crystal Report (1 bitmap, 1 Excel file).
I have created a test table in my SQL Server database that contains 2 'image' type fields. If I manually insert my OLE objects into these fields (through an Access 2000 project), then I can retrieve the dataset in code and pass it to the report. Using this approach works perfectly.
But, I need to be able to insert the OLE objects into the dataset at runtime...just before I pass the dataset to the crystal report. The bitmap and excel files are stored localy on the client computer.
I have tried using FileStream to write the data into the image fields, but I can't get it to work. Here is my code...thanks for the help.
*****Begin Code*****
// create dataset object with 'image' field
DataSet ds = daDataAccess.GetTable("Tes t");
FileStream fs = new FileStream (@"C:\LocalPic.bmp", FileMode.OpenOrCreate, FileAccess.Read);
// Read the Data into the Byte Array
byte[] MyData = new byte[fs.Length];
fs.Read(MyData, 0, (int)fs.Length);
fs.Close();
// Insert Byte Array data into 'image' field
ds.Tables[0].Rows[0]["Pict ure"] = MyData;
*****End Code*****
This approach appears to be writing some binary data to the field, but it is not a valid picture file. My crystal report will not display the contents of the field. If I write it back to the database, my Access 2000 Project shows the data as 'Long Binary Data' instead of 'Bitmap Image'. Does anyone know how to write this data, correctly, to a dataset? Thanks.
Jon
I have created a test table in my SQL Server database that contains 2 'image' type fields. If I manually insert my OLE objects into these fields (through an Access 2000 project), then I can retrieve the dataset in code and pass it to the report. Using this approach works perfectly.
But, I need to be able to insert the OLE objects into the dataset at runtime...just before I pass the dataset to the crystal report. The bitmap and excel files are stored localy on the client computer.
I have tried using FileStream to write the data into the image fields, but I can't get it to work. Here is my code...thanks for the help.
*****Begin Code*****
// create dataset object with 'image' field
DataSet ds = daDataAccess.GetTable("Tes
FileStream fs = new FileStream (@"C:\LocalPic.bmp", FileMode.OpenOrCreate, FileAccess.Read);
// Read the Data into the Byte Array
byte[] MyData = new byte[fs.Length];
fs.Read(MyData, 0, (int)fs.Length);
fs.Close();
// Insert Byte Array data into 'image' field
ds.Tables[0].Rows[0]["Pict
*****End Code*****
This approach appears to be writing some binary data to the field, but it is not a valid picture file. My crystal report will not display the contents of the field. If I write it back to the database, my Access 2000 Project shows the data as 'Long Binary Data' instead of 'Bitmap Image'. Does anyone know how to write this data, correctly, to a dataset? Thanks.
Jon
try loading the image as a Bitmap or Image instead of a byte array and passing that bitmap to the dataset
ASKER
Could you provide some sample code to show me how that would work?
you will need a field with the content type of the uploaded file
then make something like "file.aspx" :
in a web environment, it's done like this :
__________________________ ______
while(myReader.Read())
{
byte[] bData = new byte[400000];
myReader.GetBytes(1,0,bDat a,0,400000 ).ToString ();
Response.ContentType = myReader.GetString(myReade r.GetOrdin al("a_type ")) ;
Response.BinaryWrite (bData) ;
}
myCon.Close();
__________________________ _______
in your dataset, set an image tag, with as source the file.aspx with the rowid :
<img src='file.aspx?id=1'>
__________________________ _____
I don't know this will help, I dont know about Crystal reports, but it seems like you're forgetting your content type field
-> get it by : File1.PostedFile.ContentTy pe
then make something like "file.aspx" :
in a web environment, it's done like this :
__________________________
while(myReader.Read())
{
byte[] bData = new byte[400000];
myReader.GetBytes(1,0,bDat
Response.ContentType = myReader.GetString(myReade
Response.BinaryWrite (bData) ;
}
myCon.Close();
__________________________
in your dataset, set an image tag, with as source the file.aspx with the rowid :
<img src='file.aspx?id=1'>
__________________________
I don't know this will help, I dont know about Crystal reports, but it seems like you're forgetting your content type field
-> get it by : File1.PostedFile.ContentTy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.