1 Replies - 3526 Views - Last Post: 13 March 2012 - 07:15 AM Rate Topic: -----

#1 thantthiri  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-July 10

Object reference not set to an instance of an object error on report

Posted 12 March 2012 - 08:17 PM

I bind dynamically crystal report to crystal report viewer through C#.net code. and parameter is passing properly, and connection established correctly. the report shown on the report viewer successfully but also show object reference not set to an instance of an object error. how can i handle this. please check my coding .

DatabaseHelper.cs
   public static ConnectionInfo myReportConnectionInfo;
        public static string myReportUserName;
        public static string myReportUserPassword;
        public static string myReportServerName;
        public static string myReportDbName;

  
        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
                { 
                }
                 

            }
        }
==============================================================

    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);

    }

This post has been edited by Atli: 13 March 2012 - 12:51 AM
Reason for edit:: Added [code]...[/code] tags.


Is This A Good Question/Topic? 0
  • +

Replies To: Object reference not set to an instance of an object error on report

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5578
  • View blog
  • Posts: 11,931
  • Joined: 02-June 10

Re: Object reference not set to an instance of an object error on report

Posted 13 March 2012 - 07:15 AM

Quote

Object Reference Not Set To An Instance Of An Object Error


First error message explained here:
What does this error mean?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1