on 07-29-2014 3:04 PM
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);
}
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
- 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
i used the code using sessions no changes error in the same way
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.