The code also uses the previous section to remove the Datasource of the Report. Each bound field is also removed. With the foundation of the second section, it is not difficult to see this now. It is nothing more than passing a data set to the report, and binding this data set to each control to clear the Cell in the details. value, each cell is changed to the name of the corresponding column in the database for easy binding
The XReport code is as follows, the function is to bind the data
public partial class XtraReport3 : DevExpress.XtraReports.UI.XtraReport { public XtraReport3() { InitializeComponent(); } // Refactor a constructor public XtraReport3(DataTable dt) { InitializeComponent(); // The data source of the report comes from the database table this .DataSource = dt; // lebel binds the ID in the database text this .xrLabel1.DataBindings.Add( " text " ,dt, " id " ); this .xrTableCell1.DataBindings. Add( " text " ,dt, " id " ); } } }
Form1 code is as follows
private void button1_Click(object sender, EventArgs e) { string constr = "serer=192.168.100.222;uid=sa;pwd=Metel@1989;database=text"; SqlConnection con = new SqlConnection(constr); try { con.Open(); SqlDataAdapter da = new SqlDataAdapter("select * from book", con); DataTable dt = new System.Data.DataTable(); da.Fill(dt); XtraReport3 report = new XtraReport3(dt); report.Landscape = false; documentViewer1.DocumentSource = report; report.CreateDocument(); } catch (Exception) { throw; } finally { con.Close(); } }