Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Object reference not set to an instance of an object

Posted on 2012-03-21
8
Medium Priority
?
362 Views
Last Modified: 2012-03-23
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
0
Comment
Question by:ayha1999
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 37751027
Hi Ahya,

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

Kalpesh
0
 
LVL 7

Author Comment

by:ayha1999
ID: 37751056
the value is already provided as "nInt"
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 37751081
may be qReportTableAdapter object is null.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Author Comment

by:ayha1999
ID: 37751095
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
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 37751109
"select * from mytable where id= " + nInt;

Don't use Parameter direct set value into your Query. like above
0
 
LVL 7

Author Comment

by:ayha1999
ID: 37751114
my query is "select * from mytable where id=@id"

then in the code

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

Accepted Solution

by:
Kalpesh Chhatrala earned 2000 total points
ID: 37751118
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 37760068
Thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question