Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
obj.firstName = TextBox1.Text;
            obj.lastname = TextBox2.Text;
            obj.email = TextBox4.Text;
            obj.newrecruit = TextBox5.Text;
            obj.site.siteid = Convert.ToInt32(DropDownList4.SelectedValue);
            obj.manageothers = DropDownList1.SelectedValue;
            obj.topfunction.topfunctionid = Convert.ToInt32(DropDownList2.SelectedValue);
            obj.subfunction.subfunctionid = Convert.ToInt32(DropDownList3.SelectedValue);
            obj.lmsrole.lmsroleid = Convert.ToInt32(DropDownList5.SelectedValue);
            obj.channel.channelid = Convert.ToInt32(DropDownList6.SelectedValue);
            obj.employmentstatus.employmentstatusid = Convert.ToInt32(DropDownList7.SelectedValue);
            obj.status.statusid = Convert.ToInt32(DropDownList8.SelectedValue);
            obj.active = TextBox14.Text;
            obj.comments = TextBox15.Text;
            obj.localjobtitle = TextBox16.Text;
            obj.locallanguagejobtitle = TextBox17.Text;
            obj.kmlevel = Convert.ToInt32(DropDownList9.SelectedValue);
            br.viewdetails(obj);



error is coming in the 4th line...that is siteid ....this is the code to add details to database...this code is in the add button click event...can anyone plss tell why this error is coming?
Posted
Updated 14-Feb-12 17:54pm
v2
Comments
Mateen Khan 14-Feb-12 23:46pm    
Hi,
Can you please post code for the class defination of Obj. Need to usnderstand how obj.site.siteid is defined?
Sergey Alexandrovich Kryukov 14-Feb-12 23:52pm    
This is less likely reason. Anyway, I answered; take a look if you are curious... :-)
--SA
Al Moje 14-Feb-12 23:47pm    
Hi,
I think it is easy to solve if you could post what is an error thrown...
Sergey Alexandrovich Kryukov 14-Feb-12 23:48pm    
Of course. I answered though...
--SA
Sergey Alexandrovich Kryukov 14-Feb-12 23:47pm    
Very poor issue report. This is not how you should ask your questions of you hope for an answer. I explain it in my answer, please see.
--SA

1 solution

From the first glance, one of SelectedValue values is null, because nothing is selected. At least, this is the most likely reason. You should always check it for null, not assuming that some DropDownList item is always selected.

In principle, if could be something else as well, even you obj or br as you don't show where these objects are instantiated, but this is less likely.

Let me tell you that asking a question like that is not nice. What you see is really an exception. Write in your question: "exception". Write exact exception fully-qualified type name and message and comment exact line where it was thrown. Use the debugger or catch all exceptions on top of stack of your thread and dump it. For code line numbers, inspect/output Exception.Stack.

These are elementary debugging and issue reporting technique, which you really need to know and use very well, otherwise you cannot really say that you develop anything. At this moment, you are not developing yet; you are just trying to kick a TV set until it start showing the picture. It won't get you far.

—SA
 
Share this answer
 
v3
Comments
amaljosep 14-Feb-12 23:54pm    
sry 4 my bad issue report....anyway i got the solution.i didnt initialized my class obects ...thats y it was showing that erre.....thanks a lot for the quick reply...
Sergey Alexandrovich Kryukov 14-Feb-12 23:59pm    
You are welcome.
Don't apologize, better use my advice for your other questions.

Good luck, call again.
--SA
Varun Sareen 14-Feb-12 23:57pm    
good :)

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