/// <summary>
/// 数据集
/// </summary>
static Dictionary<string, string> set = new Dictionary<string, string>();
public static void ReportPrint_text(string djh)
{
set.Clear();
PageReport pageReport = new PageReport(new System.IO.FileInfo(@"C:\Users\gong\Desktop\运行时数据源.rdlx"));
foreach (var item in pageReport.Report.DataSets)
{
set.Add(item.Name, item.Query.CommandText);
item.Query.CommandText = null;
}
///参数赋值
pageReport.Report.ReportParameters[0].DefaultValue.Values.Add(djh);
string yymc ="XXXX信息";
pageReport.Report.ReportParameters[1].DefaultValue.Values.Add(yymc);
///更换数据类型及删除sql语句
pageReport.Report.DataSources[0].ConnectionProperties.DataProvider = "DATASET";//更换数据类型为dataset
pageReport.Report.DataSources[0].ConnectionProperties.ConnectString = null;
pageReport.Report.ReportParameters.Clear();
PageDocument pageDocument = new PageDocument(pageReport);
pageDocument.LocateDataSource += new LocateDataSourceEventHandler(locatedata);
pageDocument.Print(true, false, false);
}
private static void locatedata(object sender, LocateDataSourceEventArgs args)
{
foreach (var item in set)
{
if (args.DataSetName == item.Key)
{
string sql = item.Value;
args.Data = returndata(sql);
if (args.Data == null)
{
MessageBox.Show("没有数据可打印!");
return;
}
}
}
}
private static object returndata(string sql)
{
DataTable dt = new DataTable();
dt=///更近sql语句查询datatable结果
return dt;
}
上面代码要报错呢
大神帮忙完整下例子哇。sql语句里面如果有参数怎么处理。 |