读书人

CrystalReportSource1.ReportDocument

发布时间: 2012-01-20 18:53:53 作者: rapoo

CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables[0])问题!!!
请各位老大指点迷津!
protected void Button_push_Click(object sender, EventArgs e)
{

string sql = "SELECT * FROM csj_wx ";

string DBConfig_sql = @ "Data Source=SKY-0EKQQVVJ0ON;Initial Catalog=yangtze;User ID=sa;Password=hp1502... ";

//DataSet ds = new DataSet();
DataSet ds = RunQuery(sql);
SqlConnection sqlCon = new SqlConnection(DBConfig_sql);

SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);

SqlDataAdapter sqlAd = new SqlDataAdapter();

sqlAd.SelectCommand = sqlCmd;

sqlAd.Fill(ds,sql);

//Response.Write( " <script> alert( 'ok........... '); </ script> ");
CrystalReportSource1.ReportDocument.Load(Server.MapPath( "CrystalReport.rpt "));


if (ds.Tables[0].Rows.Count> 0){
try{

//ReportDocument rd = new ReportDocument();
CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables[0]);//这里出错!!!!就是没有数据,ds返回是有数据集的
//CrystalReportViewer1.ReportSource=ds;
CrystalReportSource1.DataBind();
}
catch{
Response.Write( "没有满足您查询条件的数据,请重新输入查询条件! " + ds.Tables[0].Rows.Count);
}
}






CrystalReportViewer1.ReportSource = CrystalReportSource1;

CrystalReportViewer1.DataBind();



}

[解决办法]
SqlConnection sqlCon = new SqlConnection(DBConfig_sql);

SqlCommand sqlCmd = new SqlCommand(sql, sqlCon);

SqlDataAdapter sqlAd = new SqlDataAdapter();

sqlAd.SelectCommand = sqlCmd;

sqlAd.Fill(ds,sql);
不知道你的sql是什么? 这里用表名比较好。我写水晶报表时没有遇见过你说的错误。

CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables[0]);
这里用表名比较好,如果你连接的是多个表,用你的方法肯定出错。我是用DS.Tables不知道你加[]目的是什么。 如果换不行的话 我把我的代码给你。

读书人网 >asp.net

热点推荐