//*** TableRows (DataTable) ***// protected DataTable DataTableRows() { DataTable dt = new DataTable(); DataRow dr; //*** Column ***// dt.Columns.Add("CustomerID"); dt.Columns.Add("Name"); dt.Columns.Add("Email"); dt.Columns.Add("CountryCode"); dt.Columns.Add("Budget"); dt.Columns.Add("Used"); //*** Rows ***// dr = dt.NewRow(); dr["CustomerID"] = "C001"; dr["Name"] = "Win Weerachai"; dr["Email"] = "[email protected]"; dr["CountryCode"] = "TH"; dr["Budget"] = "1000000"; dr["Used"] = "600000"; dt.Rows.Add(dr); //*** Rows ***// dr = dt.NewRow(); dr["CustomerID"] = "C002"; dr["Name"] = "John Smith"; dr["Email"] = "[email protected]"; dr["CountryCode"] = "EN"; dr["Budget"] = "2000000"; dr["Used"] = "800000"; dt.Rows.Add(dr); return dt; //*** Return DataTable ***// }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Configuration; using CrystalDecisions.CrystalReports; namespace testCrystalreport { public partial class Form1 : Form { public Form1() { InitializeComponent(); } DataTable dt = null; private void Form1_Load(object sender, EventArgs e) { this.reportViewer1.RefreshReport(); dt.Columns.Add("col1", typeof(string)); dt.Columns.Add("col2", typeof(string)); dt.Columns.Add("col3", typeof(string)); } private void button1_Click(object sender, EventArgs e) { DataRow Drre = dt.NewRow(); Drre["col1"] = "cc"; Drre["col2"] = "bb"; Drre["col3"] = "dd"; dt.Rows.Add(Drre); ReportDocument rpt = new ReportDocument(); //ตรงนี้มันไม่เจอ Class อะครับต้อง add references อะไรเข้ามาหรือเปล่าครับ string directory = Application.StartupPath; //rpt.Load(directory & "\\myCrystalReport1.rpt") rpt.Load("D:\\testCrystalreport\\myCrystalReport3.rpt"); rpt.SetDataSource(dt); this.reportViewer1.DataBindings.Equals(rpt); this.reportViewer1.Refresh(); } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง