i create a dataset at runtime and i then want to display this data in a crystal report. i get the error "Query Engine Error". i created a report called rptGETASSETS using a dataset that is empty and then fill it at run time.
here is my asp.net 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(ds, "dbo.SALFLDGSDE");
DataGrid1.DataSource = ds;
DataGrid1.DataMember = "dbo.SALFLDGSDE";
DataGrid1.DataKeyField = "ASSET_CODE";
DataGrid1.DataBind();
//ExportPDF(ds);
}
private void ExportPDF(DataSet ds)
{
rptGETASSETS crReportDocument = new rptGETASSETS();
//this.sqlDataAdapter1.Fill(ds);
crReportDocument.SetDataSource(ds);
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();
}
my stored procedure is:
CREATE PROCEDURE dbo.[stpGETASSETS]
@pFromAssetCode Char(100),
@pToAssetCode Char(100),
@pFromDate Int,
@pToDate Int
AS
--Get the required rows before the parameter to date
SELECT dbo.SSRFFVR.ASSET_CODE, dbo.SSRFFVR.NAME, dbo.SSRFFVR.START_PERD, dbo.SSRFFVR.END_PERD, dbo.SSRFFVR.BASE_GROSS, dbo.SSRFFVR.BASE_DEP, dbo.SSRFFVR.BASE_NET, dbo.SSRFFVR.ANAL_F4, dbo.SALFLDGSDE.TRANS_DATE
FROM dbo.SALFLDGSDE INNER JOIN dbo.SSRFFVR ON dbo.SALFLDGSDE.ASSET_CODE = dbo.SSRFFVR.ASSET_CODE
WHERE (dbo.SSRFFVR.ASSET_CODE BETWEEN @pFromAssetCode AND @pToAssetCode ) AND (dbo.SSRFFVR.SUN_DB = 'SDE') AND (dbo.SALFLDGSDE.TRANS_DATE < @pToDate OR dbo.SALFLDGSDE.TRANS_DATE = @pToDate) AND (dbo.SALFLDGSDE.TRANS_DATE >@pFromDate)
GROUP BY dbo.SSRFFVR.ASSET_CODE, dbo.SSRFFVR.NAME, dbo.SSRFFVR.START_PERD, dbo.SSRFFVR.END_PERD, dbo.SSRFFVR.BASE_GROSS, dbo.SSRFFVR.BASE_DEP, dbo.SSRFFVR.BASE_NET, dbo.SSRFFVR.ANAL_F4, dbo.SALFLDGSDE.ENTRY_DATE, dbo.SALFLDGSDE.TRANS_DATE
ORDER BY dbo.SSRFFVR.ASSET_CODE
GO
here is my asp.net 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(ds, "dbo.SALFLDGSDE");
DataGrid1.DataSource = ds;
DataGrid1.DataMember = "dbo.SALFLDGSDE";
DataGrid1.DataKeyField = "ASSET_CODE";
DataGrid1.DataBind();
//ExportPDF(ds);
}
private void ExportPDF(DataSet ds)
{
rptGETASSETS crReportDocument = new rptGETASSETS();
//this.sqlDataAdapter1.Fill(ds);
crReportDocument.SetDataSource(ds);
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();
}
my stored procedure is:
CREATE PROCEDURE dbo.[stpGETASSETS]
@pFromAssetCode Char(100),
@pToAssetCode Char(100),
@pFromDate Int,
@pToDate Int
AS
--Get the required rows before the parameter to date
SELECT dbo.SSRFFVR.ASSET_CODE, dbo.SSRFFVR.NAME, dbo.SSRFFVR.START_PERD, dbo.SSRFFVR.END_PERD, dbo.SSRFFVR.BASE_GROSS, dbo.SSRFFVR.BASE_DEP, dbo.SSRFFVR.BASE_NET, dbo.SSRFFVR.ANAL_F4, dbo.SALFLDGSDE.TRANS_DATE
FROM dbo.SALFLDGSDE INNER JOIN dbo.SSRFFVR ON dbo.SALFLDGSDE.ASSET_CODE = dbo.SSRFFVR.ASSET_CODE
WHERE (dbo.SSRFFVR.ASSET_CODE BETWEEN @pFromAssetCode AND @pToAssetCode ) AND (dbo.SSRFFVR.SUN_DB = 'SDE') AND (dbo.SALFLDGSDE.TRANS_DATE < @pToDate OR dbo.SALFLDGSDE.TRANS_DATE = @pToDate) AND (dbo.SALFLDGSDE.TRANS_DATE >@pFromDate)
GROUP BY dbo.SSRFFVR.ASSET_CODE, dbo.SSRFFVR.NAME, dbo.SSRFFVR.START_PERD, dbo.SSRFFVR.END_PERD, dbo.SSRFFVR.BASE_GROSS, dbo.SSRFFVR.BASE_DEP, dbo.SSRFFVR.BASE_NET, dbo.SSRFFVR.ANAL_F4, dbo.SALFLDGSDE.ENTRY_DATE, dbo.SALFLDGSDE.TRANS_DATE
ORDER BY dbo.SSRFFVR.ASSET_CODE
GO