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.A dapter.Sel ectCommand .Parameter s.AddWithV alue("@id" ,nInt.ToSt ring());
or this.qReportTableAdapter.A dapter.Sel ectCommand .Parameter s.Add("@id ",OleDbTyp e.Integer, 1).Value=n Int;
this.qReportTableAdapter.F ill (this.dsReport.qReport);
this.reportViewer1.Refresh Report ();
Please help.
Thanks ayha
this.qReportTableAdapter.A
or this.qReportTableAdapter.A
this.qReportTableAdapter.F
this.reportViewer1.Refresh
Please help.
Thanks ayha
ASKER
the value is already provided as "nInt"
may be qReportTableAdapter object is null.
ASKER
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
thanks
"select * from mytable where id= " + nInt;
Don't use Parameter direct set value into your Query. like above
Don't use Parameter direct set value into your Query. like above
ASKER
my query is "select * from mytable where id=@id"
then in the code
this.qReportTableAdapter.A dapter.Sel ectCommand .Parameter s.AddWithV alue("@id" ,nInt.ToSt ring());
then in the code
this.qReportTableAdapter.A
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
Check any one Object has null value that's why you get error.
Kalpesh