Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding OLE objects to a dataset

Posted on 2003-11-17
6
Medium Priority
?
491 Views
Last Modified: 2010-04-16
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("Test");

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]["Picture"] = 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


0
Comment
Question by:jtdagger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Agarici
ID: 9770353
try loading the image as a Bitmap or Image instead of a byte array and passing that bitmap to the dataset
0
 

Author Comment

by:jtdagger
ID: 9772040
Could you provide some sample code to show me how that would work?
0
 

Expert Comment

by:Natasja_
ID: 9802230
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,bData,0,400000).ToString();
            
                              
                              Response.ContentType = myReader.GetString(myReader.GetOrdinal("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.ContentType
0
 

Accepted Solution

by:
jtdagger earned 0 total points
ID: 10281668
I appreciate the recommendations that were made, but I wasn't able to get any of them to work correctly.

The solution I came up with was reverting back to Crystal's OLE linking feature.  This wasn't an ideal approach, but it did solve the problem.  Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question