Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im getting the Error on Binding location in DropDownList from Database on this line( 2nd line in below method that is Error line)
C#
void fun()
{
ddlcompanyname.SelectedItem.Text = Dt.Rows[0]["Company_name"].ToString();---->No Error
ddllocation.SelectedItem.Text = Dt.Rows[0]["Location"].ToString();----->Error
}

""""Object reference not set to an instance of an object.""""""
Posted
Updated 7-May-14 21:52pm
v2
Comments
Nitij 8-May-14 5:05am    
Debug the code and either hover mouse over objects to see if any of them is null or use Quick Watch to find that out.

I am glad that you mentioned the two scenarios with and without error.

In the case where you get an error, the most probable situation would be that Dt.Rows[0]["Location"]. is returned as NULL.

And on a NULL object when you try to access a method or property, you get this error.

Hope this helps!
 
Share this answer
 
Comments
phmani469 9-May-14 1:10am    
Thanks 4 ur response.....Still problem is there, location value returning from DB ....Any other suggestions
Either,

Your datatable Dt does not have a field/column called "Location" (check spelling and case)

or,

ddllocation does not have a selected item

Debug to determine which of the two possible problems is the case.

If it is the latter of the two then you can always programmatically select an item
 
Share this answer
 
Comments
phmani469 9-May-14 1:12am    
1st of all thanks for ur response....Im check those spelling all r corect...Any other suggestions
CHill60 9-May-14 3:07am    
What is the value of ddllocation.SelectedItem ... is it null?
phmani469 9-May-14 4:16am    
Finally i Did it....While loading the dropdowns Im getting the Error .....Thank u so mush to spend ur valuable time to answer my questions
CHill60 9-May-14 4:24am    
I'm glad it's working now
Also have a look at solution #2 to this question[^] posted just minutes before your own.
 
Share this answer
 
Finally I did it.....While Loading the Dropdown Location from Database...I getting Error ...Finally I encounter the Error......Thank u to all Supported me
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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