Directory
Description
File List
Procedure
Form1.cs
VB. NET
Description
The C #. Net windows program demonstrates how to create a dataset, add an image to a dataset, and pass the dataset to a subreport at runtime.
File List
-Bin/debug/canada.jpg
-Bin/debug/germany.jpg
-Bin/debug/japan.jpg
-Bin/debug/usa.jpg
-App. ICO
-Assemblyinfo. CS
-Crystalreport1.cs
-Crystalreport1.rpt
-Dynamicimage. csproj
-Dynamicimage. csproj. User
-Dynamicimage. sln
-Form1.cs
-Form1.resx
-Readme.txt
-Steps.txt
Procedure
* Start a new project/create a dataset and Its Mode
-Create a project
-Code converted to the code behind form1.cs
-Imports system. Data/system. Io
-Create the function "createdata" to create a dataset:
Dataset createdata ()
{
Dataset DATA = new dataset ();
Data. Tables. Add ("Images ");
Data. Tables [0]. Columns. Add ("country", system. type. GetType ("system. String "));
Data. Tables [0]. Columns. Add ("IMG", system. type. GetType ("system. byte []");
Data. writexmlschema (directory. getcurrentdirectory () + "// dynamicimage. XSD ");
}
-Create the function "createreport" to call createdata to create a dataset:
Void createreport ()
{
Createdata ();
}
-Call createreport In the constructor
Public form1 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();
//
// Todo: add Any constructor code after initializecomponent call
//
Createreport ();
}
-Construct and execute the program/create dynamicimage. XSD in the bin/debug folder.
* Design Report
-Project-> Add a new project
-Select Crystal Report and click "open"
-Select "as blank report" and click "OK"
-Right-click any blank space and choose database> Add/delete database"
-Expand ODBC (rdo), select Xtreme sample database, and click "finish ".
-Expand the table and double-click customer.
-Click OK"
-Drag and Drop the customer name and last year's sales to the details
-Right-click any blank space and insert-> subreport
-Place the subreport next to sales in last year's
-Select "create subreport", name the subreport as "Flags", and click "report expert"
-Expand "more data sources" and select ADO. Net (XML)
-Find dynamicimage. XSD and click "finish"
-Double-click images.
-Click "Next", double-click IMG, and click "finish"
-Click the "Link" tab.
-Double-click country and click OK"
-Resize A subreport
-Double-click a subreport to open the subreport.
-Delete Report header B and report footer B
-Right-click and choose Close subreport.
* Return to the code and write the crystal code.
-Drag the crystalreportviewer control to the form form1
-Select crystalreportviewer1, F4 (attribute)
-Modify the dock attribute and fill in
-View code
-Comment out writexmlschema (because only the dataset mode file is required when designing the report)
-Assemble the dataset in the createdata function and return the dataset.
Void addimagerow (datatable TBL, string name, string filename)
{
Filestream FS = new filestream (filename, filemode. Open );
Binaryreader BR = new binaryreader (FS );
Datarow row;
Row = TBL. newrow ();
Row [0] = Name;
Row [1] = Br. readbytes (INT) Br. basestream. Length );
TBL. Rows. Add (ROW );
BR = NULL;
FS = NULL;
}
Dataset createdata ()
{
Dataset DATA = new dataset ();
Data. Tables. Add ("Images ");
Data. Tables [0]. Columns. Add ("country", system. type. GetType ("system. String "));
Data. Tables [0]. Columns. Add ("IMG", system. type. GetType ("system. byte []");
// Data. writexmlschema (directory. getcurrentdirectory () + "// dynamicimage. XSD ");
Addimagerow (data. Tables [0], "USA", directory. getcurrentdirectory () + "// usa.jpg ");
Addimagerow (data. Tables [0], "Canada", directory. getcurrentdirectory () + "// canada.jpg ");
Addimagerow (data. Tables [0], "Germany", directory. getcurrentdirectory () + "// germany.jpg ");
Addimagerow (data. Tables [0], "Japan", directory. getcurrentdirectory () + "// japan.jpg ");
Return (data );
}
-Create a report document, pass the dataset to the subreport, and bind the report to the crystal report Viewer:
Void createreport ()
{
Crystalreport1 Cr = new crystalreport1 ();
Cr. opensubreport ("Flags"). setdatasource (createdata ());
Crystalreportviewer1.reportsource = CR;
}
Form1.cs
Using system;
Using system. drawing;
Using system. collections;
Using system. componentmodel;
Using system. Windows. forms;
Using system. Data;
Using system. IO;
Namespace dynamicimage
{
/// <Summary>
/// Summary description for form1.
/// </Summary>
Public class form1: system. Windows. Forms. Form
{
Private crystaldecisions. Windows. Forms. crystalreportviewer crystalreportviewer1;
/// <Summary>
/// Required designer variable.
/// </Summary>
Private system. componentmodel. Container components = NULL;
// Process: addimagerow
// Read the image file and add it to the table of the dataset
//
// [In] TBL data table
// Country name of country
// File Name of the filename Image
//
Void addimagerow (datatable TBL, string name, string filename)
{
Filestream FS = new filestream (filename, filemode. Open); // create a file stream
Binaryreader BR = new binaryreader (FS); // create a binary Reader
Datarow row;
// Create a new data row
Row = TBL. newrow ();
// Set the country and Image Fields
Row [0] = Name;
Row [1] = Br. readbytes (INT) Br. basestream. Length );
// Add data rows to the table
TBL. Rows. Add (ROW );
// Clear
BR = NULL;
FS = NULL;
}
// Function: createdata
// Create a dataset that contains a table with two fields: Country (string) and IMG (BLOB/byte [])
// Add four records to the table
//
Dataset createdata ()
{
Dataset DATA = new dataset ();
// Add the table 'images' to the dataset
Data. Tables. Add ("Images ");
// Add two fields
Data. Tables [0]. Columns. Add ("country", system. type. GetType ("system. String "));
Data. Tables [0]. Columns. Add ("IMG", system. type. GetType ("system. byte []");
// Create a dataset (this mode is used to design a report)
// After a report is created, the mode file is no longer required
// Data. writexmlschema (directory. getcurrentdirectory () + "// dynamicimage. XSD ");
// Add four rows
Addimagerow (data. Tables [0], "USA", directory. getcurrentdirectory () + "// usa.jpg ");
Addimagerow (data. Tables [0], "Canada", directory. getcurrentdirectory () + "// canada.jpg ");
Addimagerow (data. Tables [0], "Germany", directory. getcurrentdirectory () + "// germany.jpg ");
Addimagerow (data. Tables [0], "Japan", directory. getcurrentdirectory () + "// japan.jpg ");
Return (data );
}
// Process: createreport
// Create a report and pass the dataset
//
Void createreport ()
{
// Create a report
Crystalreport1 Cr = new crystalreport1 ();
// Pass the dataset (created by calling the createdata function) to the subreport "Flags"
Cr. opensubreport ("Flags"). setdatasource (createdata ());
// Pass the report document to the viewer
Crystalreportviewer1.reportsource = CR;
}
Public form1 ()
{
//
// Required for Windows Form Designer support
//
Initializecomponent ();
//
// Todo: add Any constructor code after initializecomponent call
//
Createreport ();
}
The following part is omitted ......
VB. NET
Http://ftp1.businessobjects.com/outgoing/products/Devzone/vbnet_win_DynamicImage.zip