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