Solved

Object reference not set to an instance of an object

Posted on 2012-03-21
8
350 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
 
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 500 total points
ID: 37751118
0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 37760068
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Auto refresh part of an MVC5 View 7 57
Excel file not created as expected 7 48
Angular JS Route 3 47
Split in Javascript 5 30
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

912 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now