-Create the function "CreateReport" to invoke Createdata to create a dataset pattern:
void CreateReport ()
{
Createdata ();
}
-Call CreateReport in the constructor
Public Form1 ()
{
//
Required for Windows Form Designer support
//
InitializeComponent ();
//
Todo:add any constructor the code after InitializeComponent call
//
CreateReport ();
}
-Constructs and executes the program/will create the dynamicimage.xsd in the Bin\Debug folder.
* Design Report
-Project-> Add New Item
-Select the Crystal and click Open
-Select "as Blank Report" and click "OK"
-Right-click any space, select database-> Add/Remove Database
-Expand ODBC (RDO), select Xtreme Sample Database, and click Finish.
-Expand Table, double-click Customer
-click "OK"
-Drag the Customer Name and last year's Sales to the details
-Right-click any space, insert-> subreport
-Place the subreport next to Sales of last year ' s
-Select "Create subreport" and name the subreport "Flags", and click Report Expert
-Extend "More data sources", select Ado.net (XML)
-Locate the dynamicimage.xsd and click Finish
-Double-click Images
-Click Next, double-click IMG, click Finish
-Click the Links tab
-Double-click Country, and clicking OK
-Resizing the subreport
-Double-click on the subreport to open the subreport
-Delete Report header B and report footer B
-Right-click-> to close the subreport
* Go back to code and write Crystal code
-Drag and drop the Crystalreportviewer control onto the form Form1
-Select CRYSTALREPORTVIEWER1,F4 (properties)
-Change Dock property, fill
-View Code
-Comment out WriteXmlSchema (because a dataset schema file is required only when designing a report)
-Assemble the dataset in the Createdata function and return it
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 in the dataset
//
[In] TBL datasheet
Country Country Name
filename of 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); Creating a binary Reader
DataRow Row;
Create a new row of data
row = tbl. NewRow ();
Set Country field and image field
Row[0] = name;
ROW[1] = br. Readbytes ((int) Br. Basestream.length);
Adding rows of data to a 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 a table
//
DataSet Createdata ()
{
DataSet data = new DataSet ();
Add table ' Images ' to a dataset
Data. Tables.add ("Images");
Create a dataset pattern (which is used to design a report)
The schema file is no longer required after the report is created
Data. WriteXmlSchema (Directory.GetCurrentDirectory () + "\\DynamicImage.xsd");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.