Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Object reference not set to an instance of an object

Posted on 2012-03-21
8
Medium Priority
?
359 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

715 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