cancel
Showing results for 
Search instead for 
Did you mean: 

Object reference not set to an instance of an object. on report viewer

Former Member
0 Kudos

Object reference not set to an instance of an object. on report viewer

the report its showing correctly

but when try to change the value of the parameter i get this error :

Object reference not set to an instance of an object

the parameter its on the left

this its the code on default.aspx.cs

            ReportDocument myReport = new ReportDocument();

            DataSet myData = new DataSet();

            MySql.Data.MySqlClient.MySqlConnection conn;

            MySql.Data.MySqlClient.MySqlCommand cmd;

            MySql.Data.MySqlClient.MySqlDataAdapter myAdapter;

            conn = new MySql.Data.MySqlClient.MySqlConnection();

            cmd = new MySql.Data.MySqlClient.MySqlCommand();

            myAdapter = new MySql.Data.MySqlClient.MySqlDataAdapter();

            conn.ConnectionString = "server=127.0.0.1;uid=root;" +

            "pwd=;database=dinis;";

            try

            {

              cmd.CommandText = "SELECT * FROM user";

              cmd.Connection = conn;

              myAdapter.SelectCommand = cmd;

              myAdapter.Fill(myData);

        

              string fullReportPath = Server.MapPath("\\Reports\\CrystalReportodbcdinis.rpt");

//  @UserId is the parameter you added at the design of the crystalReport and userid is the

              myReport.Load(fullReportPath);

   // myReport.Database.Tables(0).SetDataSource(myData.Tables(0));

   // myReport.Database.Tables(1).SetDataSource(myData.Tables(1));

              ParameterDiscreteValue paramDV_UserId = new ParameterDiscreteValue(); // Step 1

              int userid = 8;

              paramDV_UserId.Value = userid; // step 2:userid is the value for the parameters

             // myReport.SetParameterValue("Utilizador",7);

              ParameterValues currentParameterValues = new ParameterValues();

              ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();

              parameterDiscreteValue.Value = userid.ToString();

              currentParameterValues.Add(parameterDiscreteValue);

              myReport.DataDefinition.ParameterFields["Utilizador"].ApplyCurrentValues(currentParameterValues);

http://localhost:13131/Default.aspx.cs

    CrystalReportViewer1.ReportSource = myReport;

}

catch (MySql.Data.MySqlClient.MySqlException ex)

{

    Response.Write(ex.Message);

    //MessageBox.Show(ex.Message, "Report could not be created",

    //    MessageBoxButtons.OK, MessageBoxIcon.Error);

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

If it is a web application, I would suggest using HTTP sessions to store the ReportDocument object.

See this KB for reference code on how to use session.

http://search.sap.com/ui/notes?id=0001985571&boj=/sap/bc/bsp/spn/scn_bosap/notes.do?access=69765F6D6...

If that does not resolve the issue, provide below info.

- Version of CR with patch level.

- Version of VS

- Win or web app?

- What happens when you refresh the report in viewer using refresh button?

Thanks,

Bhushan

Former Member
0 Kudos

- Version of CR with patch level.

latest for vs 2013

- Version of VS

VS 2013

- Win or web app?

asp.net webforms 4.0

- What happens when you refresh the report in viewer using refresh button?

crash

with the parameter form when i try to change the id it crashes and error

  1. Object reference not set to an instance of an object

i used the code using sessions no changes error in the same way

Answers (0)