日期:2014-05-18 浏览次数:20877 次
private void Form1_Load(object sender, EventArgs e) { //推模式 string sql = "Select T1, T2, T3 FROM T where T1=''a''"; string DBConfig_sql = @"Data Source=SYWZSWL\SQLEXPRESS;Initial Catalog=Test;User ID=sa;Password=123456"; DataSet ds = new DataSet(); SqlConnection sqlCon = new SqlConnection(DBConfig_sql); SqlCommand sqlCmd = new SqlCommand(sql, sqlCon); SqlDataAdapter sqlAd = new SqlDataAdapter(); sqlAd.SelectCommand = sqlCmd; sqlAd.Fill(ds, "sql"); crystalReport1.Load(Application.StartupPath + "CrystalReport.rpt"); crystalReport1.SetDataSource(ds.Tables["sql"]); //{?}中的参数可以不用赋值,即使赋了值也不起作用。 // CrystalReportSource1.ReportDocument.ParameterFields["Parm"].CurrentValues.AddValue("1234567"); crystalReport1.ParameterFields["Title"].CurrentValues.AddValue("这时推模式的报表样例!"); crystalReportViewer1.ReportSource = crystalReport1; }