Link to home
Start Free TrialLog in
Avatar of ayha1999
ayha1999

asked on

Object reference not set to an instance of an object

I am trying to bind a reportViewer in c# 2010 windows application from Access 2007 query, the query is "select * from mytable where id=@id". I added parameters using Add and AddWithValue but both throws an error that "Object reference not set to an instance of an object." How can fix the problem?

this.qReportTableAdapter.Adapter.SelectCommand.Parameters.AddWithValue("@id",nInt.ToString());

or this.qReportTableAdapter.Adapter.SelectCommand.Parameters.Add("@id",OleDbType.Integer,1).Value=nInt;

this.qReportTableAdapter.Fill (this.dsReport.qReport);
this.reportViewer1.RefreshReport ();  

Please help.

Thanks ayha
Avatar of Kalpesh Chhatrala
Kalpesh Chhatrala
Flag of India image

Hi Ahya,

Check any one Object has null value that's why you get error.

Kalpesh
Avatar of ayha1999
ayha1999

ASKER

the value is already provided as "nInt"
may be qReportTableAdapter object is null.
where is the right place to add the parameter?  If I remove 'where' condition from the query and ádd parameter'from the code, it works without error.

thanks
"select * from mytable where id= " + nInt;

Don't use Parameter direct set value into your Query. like above
my query is "select * from mytable where id=@id"

then in the code

this.qReportTableAdapter.Adapter.SelectCommand.Parameters.AddWithValue("@id",nInt.ToString());
ASKER CERTIFIED SOLUTION
Avatar of Kalpesh Chhatrala
Kalpesh Chhatrala
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks