映射“DataAdapter.TableMappings”
映射“DataAdapter.TableMappings”
TableMappings为映射,如果单表映射水晶报表的话,代码直接可以这样子写就可以显示数据在crystalReportViewer1上了。主要代码如下:
da = new SqlDataAdapter("SELECT * FROM InStock_Detail", conn); da.TableMappings.Add("Table", "InStock_Detail"); da.Fill(mydata, "InStock_Detail");//, "InStock_Detail" DBReport.InCrystalReport cr = new DBReport.InCrystalReport(); cr.SetDataSource(mydata); crystalReportViewer1.ReportSource = cr;
如果是两表映射水晶报表的话,代码则要这样子写才能够实现,代码如下:
da = new SqlDataAdapter("SELECT * FROM InStock_Detail,InStock where InStock.voucher_no=InStock_Detail.voucher_no", conn); da.TableMappings.Add("Table", "InStock_Detail");//Table名称唯一 da.TableMappings.Add("Table1", "InStock");//Table1名称唯一
da.Fill(mydata, "InStock_Detail");//, "InStock_Detail"
da.Fill(mydata, "InStock");
DBReport.InCrystalReport cr = new DBReport.InCrystalReport();
cr.SetDataSource(mydata);
crystalReportViewer1.ReportSource = cr;