Click here to Skip to main content
12,625,607 members (33,623 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
protected void btnSave_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("exec insertMission @fonction,@service,@missionObj,@excpecteRslt,@startDate,@returnDate,@District_code,@codeFinance,@empno,
@transNum", con);
            cmd.Parameters.AddWithValue("@fonction",txtFonction.Text);
            cmd.Parameters.AddWithValue("@service",txtService.Text);
            cmd.Parameters.AddWithValue("@missionObj",txtObject.Text);
            cmd.Parameters.AddWithValue("@excpecteRslt",txtResult.Text);
            cmd.Parameters.AddWithValue("@startDate",txtStartDate.Text);
            cmd.Parameters.AddWithValue("@returnDate",txtEndDate.Text);
            cmd.Parameters.AddWithValue("@District_code",DropDownListDistr.SelectedValue);
            cmd.Parameters.AddWithValue("@codeFinance",DropDownListFinance.SelectedValue);
            cmd.Parameters.AddWithValue("@empno", DropDownList1.SelectedValue);
            cmd.Parameters.AddWithValue("@transNum",DropDownListTrans.SelectedValue);           
            con.Close();
            con.Open();
            cmd.ExecuteNonQuery();
        }
Posted 13-Feb-13 8:38am
Updated 13-Feb-13 8:39am
v2
Comments
ryanb31 13-Feb-13 13:48pm
   
Which line causes it? It's possible that SelectedValue on a dropdown is null, likely because of an empty dropdown.
Gilbertinino 13-Feb-13 13:51pm
   
cmd.Parameters.AddWithValue("@codeFinance",DropDownListFinance.SelectedValue);
error is on this line
ryanb31 13-Feb-13 13:55pm
   
So, the selectedvalue is null. You need to handle that in the code.
Sergey Alexandrovich Kryukov 12-Mar-13 15:40pm
   
As I can see now, a re-post. This is another abuse.
Please, do you ever read what people advise you?
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You did not show where the exception with the message "Object reference not set to an instance of an object" is thrown.

Not to worry. This is one of the very easiest cases to detect and fix. It simply means that some member/variable of some reference type is dereferenced by using and of its instance (non-static) members, which requires this member/variable to be non-null, but in fact it appears to be null. Simply execute it under debugger, it will stop the execution where the exception is thrown. Put a break point on that line, restart the application and come to this point again. Evaluate all references involved in next line and see which one is null while it needs to be not null. After you figure this out, fix the code: wither make sure the member/variable is properly initialized to a non-null reference, or check it for null and, in case of null, do something else.

Please see also: want to display next record on button click. but got an error in if condition of next record function "object reference not set to an instance of an object"[^].

Good luck,
—SA
  Permalink  
Comments
Maciej Los 13-Feb-13 16:37pm
   
BTW, your answer deserve for 5!
Sergey Alexandrovich Kryukov 13-Feb-13 16:49pm
   
Oh, thank you, Maciej.
—SA
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

You already received an explanation in am getting this error while am running this code below "Object reference not set to an instance of an object."[^] (your previous question). If you do not understand this message then you really need to get your study guides out again, and learn about references in .NET.
  Permalink  
Comments
Sergey Alexandrovich Kryukov 13-Feb-13 15:56pm
   
A fair point, actually. My 5. As I say, this problem is one of the easiest to spot and fix.
—SA
Marcus Kramer 13-Feb-13 16:03pm
   
My 5
Maciej Los 13-Feb-13 16:41pm
   
+5!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Read this[^] and this[^]. There you'll find the an answer.
  Permalink  
Comments
Sergey Alexandrovich Kryukov 13-Feb-13 14:32pm
   
I'm afraid both posts are not concentrated enough on the nature of the issue, cloud the issue with example not very much relevant application-specific detail.
I have my simple way of explaining this simple matter. Please see my answer. What do you think?
—SA
Maciej Los 13-Feb-13 14:42pm
   
In Poland we said: Jakie pytanie, taka odpowiedź. I'll try to translate it as good as i can: "An answer is as good as a question".
Sergey Alexandrovich Kryukov 13-Feb-13 14:51pm
   
I immediately understood what Polish saying means, even though my knowledge in Slavic languages is limited. (Some people who learned some 3 different Slavic languages, such as Russian, Ukrainian and Belorussian, claimed that that could understand any other Slavic language pretty well...)
—SA
Maciej Los 13-Feb-13 15:27pm
   
I'am a man who learned only Russian language from Slavic languages (and of course Polish as a mother tongue). Congrats for knowledge of 3 Slavic languages!
Sergey Alexandrovich Kryukov 13-Feb-13 15:55pm
   
You probably did not understand: this is not about me... I know very many words, due to general linguistic experience and interest, but don't really understand the speech.
Interestingly, the how quickly understanding grows: I used to watch Ukrainian TV via youtube, and started to understand more. Many people there speak a lot in Russian though, dialects or something pretty close to "good" Russian (at least on TV), but "official" speech is supposed to be in Ukraine. We watched "Ukraine mae talant" (well, you understand), this program exist in very many countries, but in Ukraine it's especially nice, much better than average, I think...
—SA
Maciej Los 13-Feb-13 16:36pm
   
Sorry, my mistake. I thought you were talking about you. As for tv programme "Mam talent", it's really good, no matter which country edition. I saw Ukrainian edition and i agree with you, it's much better then average.

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


Advertise | Privacy | Mobile
Web01 | 2.8.161205.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100