I try to bind dynamically the crystal report to the viewer . report is shown on the crystal report viewer successfully but object reference is not set to an instance of an object error is also occured on crystal report viewer .connection also estaiblish properly and parameter values passing through correctly! what should i do? please check my coding
private void ConfigureReports(ArrayList valuesLists,ArrayList parameterLists)
{
rptReportViewer.RefreshReport();
DataBaseHelper.myReportConnectionInfo = new ConnectionInfo();
DataBaseHelper.defineConnection = null;
DataSet connectionstring = DataBaseHelper.RunSQL("SELECT TOP 1 * FROM SV_MASTER_REPORT WHERE REPORT_ID=" + rdoReportName.SelectedValue.ToString());
DataBaseHelper.myReportConnectionInfo.UserID= connectionstring.Tables[0].Rows[0]["DB_USERID"].ToString();
DataBaseHelper.myReportConnectionInfo.Password = connectionstring.Tables[0].Rows[0]["DB_PASSWORD"].ToString();
DataBaseHelper.myReportConnectionInfo.ServerName = connectionstring.Tables[0].Rows[0]["DB_SERVERNAME"].ToString();
DataBaseHelper.myReportConnectionInfo.DatabaseName = connectionstring.Tables[0].Rows[0]["DB_NAME"].ToString();
reportDouc = new ReportDocument();
string reportPath = Server.MapPath(connectionstring.Tables[0].Rows[0]["REPORT_PATH"].ToString());
reportDouc.Load(reportPath);
reportDouc.FileName = reportPath;
for (int paracount = 0; valuesLists.Count > paracount; paracount++)
{
SetCurrentValuesForParameterField(reportDouc, valuesLists[paracount].ToString(), parameterLists[paracount].ToString());
}
rptReportViewer.ReportSource = reportDouc;
DataBaseHelper.SetDBLogonReport(DataBaseHelper.myReportConnectionInfo, reportDouc);
}
public void SetCurrentValuesForParameterField(ReportDocument reportDocument,string value, string strParameter)
{
ParameterValues currentParameterValues = new ParameterValues();
ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
parameterDiscreteValue.Value = value.ToString();
currentParameterValues.Add(parameterDiscreteValue);
ParameterFieldDefinitions parameterFieldDefinitions = reportDocument.DataDefinition.ParameterFields;
ParameterFieldDefinition parameterFieldDefinition = parameterFieldDefinitions[strParameter];
parameterFieldDefinition.ApplyCurrentValues(currentParameterValues);
}
public static void SetDBLogonReport(ConnectionInfo myconnectionInfo, ReportDocument myreportDocument)
{
string[] sparams = new string[]{ };
Tables myTables = myreportDocument.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in myTables)
{
TableLogOnInfo myTablelogonInfo = table.LogOnInfo;
myTablelogonInfo.ConnectionInfo = myconnectionInfo;
table.ApplyLogOnInfo(myTablelogonInfo);
try
{
bool b = table.TestConnectivity();
if (!b)
{
}
}
catch
{
}
}
}