Click here to Skip to main content
15,881,803 members

Object reference not set to an instance of an object.

JayantaChatterjee asked:

Open original thread
I am getting this error Object reference not set to an instance of an object. when I run a form which shows the Crystal Report after button click.
My Button Click Event code is:
Data_Conn DC = new Data_Conn(Application.StartupPath);
            button1.Enabled = false;
            button1.Text = "Openning..";
           
            try
            { 
                Application.DoEvents();
                if (checkBox1.Checked)
                {
                    DC.SelectSta("select comName,iType,iName,(qty & ' ' &  unit) as qtyU,mrp,sealBscVATrs,unitPri from StockDetails sd,ItemsTbl it where it.iCode=sd.iCode;", "StockDetails");
                }               
                else
                {                   
                    button1.Text = "Report";
                    button1.Enabled = true;
                    return;
                }
                if (DC.getDataSet.Tables["StockDetails"].Rows.Count > 0)
                {
                    //MessageBox.Show("Working");

                    StockDataSet SDS = new StockDataSet();
                    DC.getAdapter.Fill(SDS);
                    StockReport StR = new StockReport();
                    StR.SetDataSource(SDS.Tables[1]);
                    StR.Refresh();
                    showReport SR = new showReport();
                    SR.crystalReportViewer1.ReportSource = StR;
                    SR.crystalReportViewer1.Refresh();
                    
SR.MdiParent = this.MdiParent;
                    SR.Show();                    
                }
                else
                {
                    MessageBox.Show("Items not Found!!", "Winform App", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

The interesting thing is, when I run in debugging mode(F11) then it will show the records in report(no error), but when I run without debugging mode(F5) then it will give that error...
the error show the code which in Program.cs file :
Application.Run(new Form1());

the source of this error is: CrystalDecisions.Windows.Forms(I checked it from view details).

Please Help me..

Thanks in advanced...
Regards
Jayanta.
Tags: C# (C# 4.0), Windows Forms, CrystalReports

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900