i create an XML dataset in visual studio. this uses two tables and is empty. this dataset is called ds. i then fill the dataset at runtime because the stored procedure that populates the dataset returns rows depending on 4 parameters that the user selects from drop dowm lists. the dataset is returned correctly in a datagrid on the webform. i then created a crystal report that uses the XML ADO.NET blank dataset that is filled at runtime. the dataset is exported to PDF but the report is blank - just the headings for the columns show up but no the dataset. Please help!
here is my c# code:
private void Button1_Click(object sender, System.EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Value;
SqlConnection conn = new SqlConnection("data source=NT20;initial catalog=SUN426ADB;integrated security=SSPI;persist security info=False;workstation id=PC2677;packet size=4096");
SqlDataAdapter da;
//DataSet ds;
SqlParameter workParam;
da = new SqlDataAdapter("stpGETASSETS", conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
workParam = new SqlParameter("@pFromAssetCode", System.Data.SqlDbType.Char);
workParam.Direction = ParameterDirection.Input;
workParam.Value =DropDownList2.SelectedItem.Value;
da.SelectCommand.Parameters.Add(workParam);
workParam = new SqlParameter("@pToAssetCode", System.Data.SqlDbType.Char);
workParam.Direction = ParameterDirection.Input;
workParam.Value = DropDownList3.SelectedItem.Value;
da.SelectCommand.Parameters.Add(workParam);
workParam = new SqlParameter("@pFromDate", System.Data.SqlDbType.Int);
workParam.Direction = ParameterDirection.Input;
string [] arStart;
arStart = dtsStartDate.SelectedDate.Date.ToString().Remove(10,9).Split('/');
string strStartDate = arStart[2]+arStart[1]+arStart[0];
int iStartDate = Convert.ToInt32(strStartDate);
workParam.Value = iStartDate;
da.SelectCommand.Parameters.Add(workParam);
workParam = new SqlParameter("@pToDate", System.Data.SqlDbType.Int);
workParam.Direction = ParameterDirection.Input;
string [] arEnd;
arEnd = dtsEndDate.SelectedDate.Date.ToString().Remove(10,9).Split('/');
string strEndDate = arEnd[2]+arEnd[1]+arEnd[0];
int iEndDate = Convert.ToInt32(strEndDate);
workParam.Value = iEndDate;
da.SelectCommand.Parameters.Add(workParam);
//ds = new DataSet();
da.Fill(ds1, "dbo.SSRFFVR");
da.Fill(ds1, "dbo.SALFLDGSDE");
DataGrid1.DataSource = ds1;
//DataGrid1.DataMember = "dbo.SSRFFVR";
//DataGrid1.DataKeyField = "ASSET_CODE";
DataGrid1.DataBind();
ExportPDF(ds1);
}
private void ExportPDF(ds1)
{
rptGETASSETS crReportDocument = new rptGETASSETS();
//this.sqlDataAdapter1.Fill(ds);
crReportDocument.SetDataSource(ds1);
//CrystalReportViewer1.ReportSource = crReportDocument;
string ExportPath;
ExportPath = Request.PhysicalApplicationPath;
crDiskFileDestinationOptions = new DiskFileDestinationOptions();
crExportOptions = crReportDocument.ExportOptions;
string fName = Session.SessionID.ToString() +".pdf";
crDiskFileDestinationOptions.DiskFileName = ExportPath + fName;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
crReportDocument.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(fName);
Response.Flush();
Response.Close();
}
here is my c# code:
private void Button1_Click(object sender, System.EventArgs e)
{
Label2.Text = DropDownList2.SelectedItem.Value;
SqlConnection conn = new SqlConnection("data source=NT20;initial catalog=SUN426ADB;integrated security=SSPI;persist security info=False;workstation id=PC2677;packet size=4096");
SqlDataAdapter da;
//DataSet ds;
SqlParameter workParam;
da = new SqlDataAdapter("stpGETASSETS", conn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
workParam = new SqlParameter("@pFromAssetCode", System.Data.SqlDbType.Char);
workParam.Direction = ParameterDirection.Input;
workParam.Value =DropDownList2.SelectedItem.Value;
da.SelectCommand.Parameters.Add(workParam);
workParam = new SqlParameter("@pToAssetCode", System.Data.SqlDbType.Char);
workParam.Direction = ParameterDirection.Input;
workParam.Value = DropDownList3.SelectedItem.Value;
da.SelectCommand.Parameters.Add(workParam);
workParam = new SqlParameter("@pFromDate", System.Data.SqlDbType.Int);
workParam.Direction = ParameterDirection.Input;
string [] arStart;
arStart = dtsStartDate.SelectedDate.Date.ToString().Remove(10,9).Split('/');
string strStartDate = arStart[2]+arStart[1]+arStart[0];
int iStartDate = Convert.ToInt32(strStartDate);
workParam.Value = iStartDate;
da.SelectCommand.Parameters.Add(workParam);
workParam = new SqlParameter("@pToDate", System.Data.SqlDbType.Int);
workParam.Direction = ParameterDirection.Input;
string [] arEnd;
arEnd = dtsEndDate.SelectedDate.Date.ToString().Remove(10,9).Split('/');
string strEndDate = arEnd[2]+arEnd[1]+arEnd[0];
int iEndDate = Convert.ToInt32(strEndDate);
workParam.Value = iEndDate;
da.SelectCommand.Parameters.Add(workParam);
//ds = new DataSet();
da.Fill(ds1, "dbo.SSRFFVR");
da.Fill(ds1, "dbo.SALFLDGSDE");
DataGrid1.DataSource = ds1;
//DataGrid1.DataMember = "dbo.SSRFFVR";
//DataGrid1.DataKeyField = "ASSET_CODE";
DataGrid1.DataBind();
ExportPDF(ds1);
}
private void ExportPDF(ds1)
{
rptGETASSETS crReportDocument = new rptGETASSETS();
//this.sqlDataAdapter1.Fill(ds);
crReportDocument.SetDataSource(ds1);
//CrystalReportViewer1.ReportSource = crReportDocument;
string ExportPath;
ExportPath = Request.PhysicalApplicationPath;
crDiskFileDestinationOptions = new DiskFileDestinationOptions();
crExportOptions = crReportDocument.ExportOptions;
string fName = Session.SessionID.ToString() +".pdf";
crDiskFileDestinationOptions.DiskFileName = ExportPath + fName;
crExportOptions.DestinationOptions = crDiskFileDestinationOptions;
crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
crReportDocument.Export();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.WriteFile(fName);
Response.Flush();
Response.Close();
}