This article to answer the post made: http://topic.csdn.net/u/20090524/15/911fd15a-32c6-4be9-9aa1-3ee95365e7e3.html
There is no new content, mainly how to read local images and display them in reports.
For cr xi and later versions, you can use a simpler method. For more information, see another simple solution for dynamic loading of Crystal Report images.
The method in this article is: how to dynamically load the image file version in the Crystal Report (image file version and database version.
This article applies to Crystal Reports of vs2003 and vs2005, and of course applies to Cr XI and later versions, which is annoying.
This article uses vs2005 and its own Crystal Reports.
Here, I will refine the proposition:
There is already a complete report. Now the report needs to load a local disk image as the logo. The logo in the report automatically changes as the local image changes.
Generally, we insert a pictureobject to insert a disk image. However, after the image is inserted, it becomes a copy of the report, so that it cannot be changed.
1: first, we have a complete crystal report application for a single table.
2: Create a New mylogo table in dataset to attach a local image.
Put two fields in it. The field type is system. byte [] or system. sbyte [].
Note: Only system. byte and system. sbyte are supported by default.
This mylogo is an intermediary. We read the local image into this table, and the crystal report reads the image display from this table.
3: Add a subreport to an existing report. The data source is the mylogo.
Drag two fields to the subreport.
4:CodeSegment is like this
1 // Set Data Source Information
2 Dataset1 ds1 = New Dataset1 ();
3 Oledbdataadapter da = New Oledbdataadapter ();
4 String connstr = " Provider = Microsoft. Jet. oledb.4.0; Data Source = " + Server. mappath ( " ~ /App_data/test. MDB " ) + " ; " ;
5 Oledbconnection CN = New Oledbconnection (connstr );
6
7
8 // Obtain the record set. Note that the final acquired record set must be consistent with the XSD structure!
9 Da = New Oledbdataadapter ( " Select employeeid1 as employeeid, employeename1 as employeename from employee1 " , CN );
10 Da. Fill (ds1, " Employee " );
11
12 // Write the local image to the dataset first
13
14 // Read the image to stream and convert it to byte []
15 // Image 1
16 Filestream fs1 = New Filestream ( @" C: \ 1.bmp " , Filemode. Open, fileaccess. Read );
17 Binaryreader br1 = New Binaryreader (fs1 );
18 Byte [] Bt1 = Br1.readbytes (( Int ) Fs1.length );
19 // Image 2
20 Filestream fs2 = New Filestream ( @" C: \ a2.jpg " , Filemode. Open, fileaccess. Read );
21 Binaryreader Br2 = New Binaryreader (fs2 );
22 Byte [] Bt2 = Br2.readbytes (( Int ) Fs2.length );
23
24 Fs1.close ();
25 Fs2.close ();
26 // Write to ds1 (only 1 line)
27 Ds1.mylogo. addmylogorow (Bt1, bt2 );
28
29
30 // The data section is not related to reports.
31 // -----------------------------------------------------------
32 // The report section is as follows:
33
34 // Use report objects to load reports
35
36 String Reportpath = Server. mappath ( " ~ /App_data/crystalreport1.rpt " );
37 Myreport. Load (reportpath );
38 // Bind a dataset. Note that a report uses a dataset.
39 Myreport. setdatasource (ds1 );
40 Crystalreportviewer1.reportsource = Myreport;
5: the effect is as follows: