Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai to All,


In my project i am trying to give data base connection to the grid view it shows the following error: "Object reference is not set to an instance of an object" please healp me .


thank you
Posted
Updated 24-Aug-11 20:20pm
v2
Comments
Uday P.Singh 25-Aug-11 2:21am    
where is your code? post it, to help you better.
Prerak Patel 25-Aug-11 2:21am    
Share some code.

The problem is arising as you are using an object with out making new object(ie with new key word)

Try This or compare it with your code

C#
SqlConnection con=new SqlConnection(//connectionstring);
con.Open();
SqlCommand cmd=new SqlCommand();
DataSet ds=new DataSet();
cmd.CommandText="select * from table";
cmd.Connection=con;
SqlDataAdapter ad=new SqlDataAdapter();
ad.Fill(ds);

Gridview.DataSource=ds.Tables[0];
GridView.Databind();
 
Share this answer
 
v2
This error occurs beacuse Null Reference. Just debug your code , possibly there is some fault in your code while handling objects.
It generally happens when you try to refernce some object which is Null/Nothing.
Please check whether your connection is properly initialzed or your datareader/dataset is fetching any value from database or not.
Just debug the code properly and the solution is there within it only :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900