水晶报表的问题
怎么让水晶报表按条件执行,我用datagrid来查看某一条数据的报表,但是显示了全部数据,不知道为什么?
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
this.myRPDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
if (!this.IsPostBack) //页面首次加载时执行
{
string str="";
if (Request.QueryString["ID"]!=null) //如果传递的参数不为空
{
str=Request.QueryString["ID"].ToString(); //取出传递过来的参数ID
//BindData(str);
this.PageBind (str);
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void PageBind(string str)
{
String sqlComm = "select id,sq_department,sq_time,sq_people,shenhe_people,shenhe_time,pizhun_people,pizhun_time,excute_department,excute_time,wz_name,wz_xh,wz_danwei,sq_num,hezhun_num,beizhu from [lsh_cg_plan] where temp_cg_id = '"+str+"'";
this.myRPDoc.Load( Server.MapPath( "CryReports/temp_caigou.rpt" ) );
//SqlConnection myConn = new SqlConnection( "server=192.168.200.116;database=asset;User Id=sa;pwd=sa" );
//string con = ConfigurationSettings.AppSettings["DBConnectionString"];
string con = "server=(local);database=lyjxc;User id=sa;Pwd=''";
SqlConnection myConn = new SqlConnection (con);
myConn.Open ();
DataSet myDs = new DataSet();
this.getTableData( sqlComm,ref myDs,"lsh_cg_plan",myConn );
this.myRPDoc.SetDataSource( myDs );
this.CrystalReportViewer1.ReportSource = this.myRPDoc;
this.CrystalReportViewer1.DataBind();
myConn.Close ();
}
protected bool getTableData( String strCommand , ref DataSet myDataSet , String TableName , SqlConnection sqlConn )
{
bool returnValue = true;
SqlCommand myCommand = new SqlCommand( strCommand,sqlConn );
SqlDataAdapter myAdapter = new SqlDataAdapter( myCommand );
try
{
myAdapter.Fill( myDataSet,TableName );
}
catch
{
returnValue = false;
}
return returnValue;
}