DEVEXPRESS XtraReport 制作报表只显示一行数据问题
C# 运用DEVEXPRESSXtraReport 制作报表,FORM 窗体中放置3个TEXTBOX.TEXT 一个BUTTON(打印)
button 下代码为:
private void button1_Click(object sender, EventArgs e)
{
string cnStr = System.Configuration.ConfigurationSettings.AppSettings["Connstr"];
SqlConnection cn = new SqlConnection(cnStr);
string Sql = "SELECT scandata.gch,gcda.gcm,tdh,bh,cast(sl as int)as sl, COUNT(stationName) AS zysl,barcode1,cc ,ys, bzl,zc,stationName FROMdbo.ScanData left join gcda onscandata.gch=gcda.gch where 1=1";
if (textBox1.Text != "")
{
Sql = Sql + " and scandata.gch='" + textBox1.Text + "'";
}
if (textBox2.Text != "")
{
Sql = Sql + " and tdh='" + textBox2.Text + "'";
}
if (textBox3.Text != "")
{
Sql = Sql + " and bh='" + textBox3.Text + "'";
}
Sql = Sql + " GROUP BYbarcode1,stationName, sl, zc, bzl, cl, ys, cc, scandata.gch,scandata.dh,gcda.gcm,tdh, bh order by bh ";
DataSet ds = new DataSet();
SqlCommand sqlcmd = new SqlCommand(Sql, cn);
SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
da.Fill(ds, "scandata");
XtraReport1 report = new XtraReport1(ds);
if (ds.Tables.Rows.Count != 0)
{
report.DataSource = ds.Tables;
report.ShowPreview();
}
}
xtraReport1 代码为:
public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
{
public XtraReport1(DataSet ds)
{
InitializeComponent();
SetDataBind(ds);
}
private void SetDataBind(DataSet ds)//绑定数据源
{
DataSource = ds;
this.xrTableCell1.DataBindings.Add("Text", DataSource, "gch");
this.xrTableCell2.DataBindings.Add("Text", DataSource, "tdh");
this.xrTableCell3.DataBindings.Add("Text", DataSource, "sl");
}
private DataSet GetTempDataSet()
{
DataSet ds = new DataSet();
string cnStr = System.Configuration.ConfigurationSettings.AppSettings["Connstr"];
SqlConnection cn = new SqlConnection(cnStr);
string Sql = "SELECT scandata.gch,gcda.gcm,tdh,bh,cast(sl as int)as sl, COUNT(stationName) AS zysl,barcode1,cc ,ys, bzl,zc,stationName FROMdbo.ScanData left join gcda onscandata.gch=gcda.gchGROUP BYbarcode1,stationName, sl, zc, bzl, cl, ys, cc, scandata.gch,scandata.dh,gcda.gcm,tdh, bh order by bh";
SqlCommand sqlcmd = new SqlCommand(Sql, cn);
SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
da.Fill(ds, "scandata");
return ds;
}
}
可是查询的结果只有 一行数据,
为什么?
什么构造函数,我不是懂
麻烦高手指点,我只想做个依据条件打印的单据 ,做了两天,实在没法,特来询问,谢谢 !
这都什么玩意?
发帖求助也请你用心点好么? 不好意思,第一次发帖
BUTTON代码
private void button1_Click(object sender, EventArgs e)
{
string cnStr = System.Configuration.ConfigurationSettings.AppSettings["Connstr"];
SqlConnection cn = new SqlConnection(cnStr);
string Sql = "SELECT scandata.gch,gcda.gcm,tdh,bh,cast(sl as int)as sl, COUNT(stationName) AS zysl,barcode1,cc ,ys, bzl,zc,stationName FROMdbo.ScanData left join gcda onscandata.gch=gcda.gch where 1=1";
if (textBox1.Text != "")
{
Sql = Sql + " and scandata.gch='" + textBox1.Text + "'";
}
if (textBox2.Text != "")
{
Sql = Sql + " and tdh='" + textBox2.Text + "'";
}
if (textBox3.Text != "")
{
Sql = Sql + " and bh='" + textBox3.Text + "'";
}
Sql = Sql + " GROUP BYbarcode1,stationName, sl, zc, bzl, cl, ys, cc, scandata.gch,scandata.dh,gcda.gcm,tdh, bh order by bh ";
DataSet ds = new DataSet();
SqlCommand sqlcmd = new SqlCommand(Sql, cn);
SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
da.Fill(ds, "scandata");
XtraReport1 report = new XtraReport1(ds);
if (ds.Tables.Rows.Count != 0)
{
report.DataSource = ds.Tables;
report.ShowPreview();
}
}
xtraReport1 代码为:
public partial class XtraReport1 : DevExpress.XtraReports.UI.XtraReport
{
public XtraReport1(DataSet ds)
{
InitializeComponent();
SetDataBind(ds);
}
private void SetDataBind(DataSet ds)//绑定数据源
{
DataSource = ds;
this.xrTableCell1.DataBindings.Add("Text", DataSource, "gch");
this.xrTableCell2.DataBindings.Add("Text", DataSource, "tdh");
this.xrTableCell3.DataBindings.Add("Text", DataSource, "sl");
}
private DataSet GetTempDataSet()
{
DataSet ds = new DataSet();
string cnStr = System.Configuration.ConfigurationSettings.AppSettings["Connstr"];
SqlConnection cn = new SqlConnection(cnStr);
string Sql = "SELECT scandata.gch,gcda.gcm,tdh,bh,cast(sl as int)as sl, COUNT(stationName) AS zysl,barcode1,cc ,ys, bzl,zc,stationName FROMdbo.ScanData left join gcda onscandata.gch=gcda.gchGROUP BYbarcode1,stationName, sl, zc, bzl, cl, ys, cc, scandata.gch,scandata.dh,gcda.gcm,tdh, bh order by bh";
SqlCommand sqlcmd = new SqlCommand(Sql, cn);
SqlDataAdapter da = new SqlDataAdapter(sqlcmd);
da.Fill(ds, "scandata");
return ds;
}
} 我的report.ShowPreview(); 方法,死活都点不出来,什么情况?
页:
[1]